DependencyProperty.UnsetValue using template and MultiBinding - c#

Anyone knows why I receive the error: "DependencyProperty.UnsetValue" when I call my Command through the Template
This is my template:
<DataTemplate x:Key="MenuComboBoxItemTemplate" DataType="ComboBox">
<DockPanel>
<TextBlock DockPanel.Dock="Left" Text="{Binding Text.Display}" />
<Button x:Name="RemoveButton"
Style="{StaticResource DeleteButton}"
DockPanel.Dock="Right"
ToolTip="Delete"
HorizontalAlignment="Right"
Padding="2"
Margin="3,0,0,0"
Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl},AncestorLevel=1}, Path=DataContext.RemoveMenuItemCommand}">
<Button.CommandParameter>
<MultiBinding Converter="{StaticResource MultiValueConverter}">
<Binding Path="Name" RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type menus:MenuComboBox}}" />
<Binding />
</MultiBinding>
</Button.CommandParameter>
<Image Source="{dx:DXImageOffice2013 Image=Delete_16x16.png}" />
</Button>
</DockPanel>
</DataTemplate>
My combobox:
<menus:MenuComboBox
x:Name="MyItems"
Grid.Column="0"
Grid.Row="2"
Padding="6,3,5,3"
BorderThickness="1"
Text="{Binding MyItems, UpdateSourceTrigger=LostFocus}"
ItemTemplate="{StaticResource MenuComboBoxItemTemplate}"
ItemsSource="{Binding Menus[MyItems].Items}"
NewMenuItemCommand="{Binding AddMenuItemCommand}"
GotFocusCommand="{Binding GotFocusCommand}" />
I am stuck on it :(

Related

WPF: Align TextBlock with different font sizes at top

I need to align two text elements of different font sizes at the top line.
All I managed so far is either this :
Resulting from this code:
<Canvas VerticalAlignment="Center" HorizontalAlignment="Center" SnapsToDevicePixels="True">
<StackPanel x:Name="RemainingTimeDisplay" Orientation="Horizontal" VerticalAlignment="Top">
<StackPanel.Margin>
<MultiBinding Converter="{StaticResource CenterConverter}">
<Binding ElementName="RemainingTimeDisplay" Path="ActualWidth"/>
<Binding ElementName="RemainingTimeDisplay" Path="ActualHeight"/>
</MultiBinding>
</StackPanel.Margin>
<!--<Run FontSize="360" Text="{Binding RemainingTime.Minutes, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay, UpdateSourceTrigger=PropertyChanged, StringFormat=D2, Converter={StaticResource IntAbsConverter}}"/>
<Run FontSize="128" Text="{Binding RemainingTime.Seconds, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay, UpdateSourceTrigger=PropertyChanged, StringFormat=D2, Converter={StaticResource IntAbsConverter}}"/>-->
<TextBlock FontSize="360" Text="{Binding RemainingTime.Minutes, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay, UpdateSourceTrigger=PropertyChanged, StringFormat=D2, Converter={StaticResource IntAbsConverter}}"/>
<TextBlock FontSize="128" Text="{Binding RemainingTime.Seconds, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay, UpdateSourceTrigger=PropertyChanged, StringFormat=D2, Converter={StaticResource IntAbsConverter}}"/>
</StackPanel>
</Canvas>
Or:
<Canvas VerticalAlignment="Center" HorizontalAlignment="Center" SnapsToDevicePixels="True">
<StackPanel x:Name="RemainingTimeDisplay" Orientation="Horizontal" VerticalAlignment="Top">
<StackPanel.Margin>
<MultiBinding Converter="{StaticResource CenterConverter}">
<Binding ElementName="RemainingTimeDisplay" Path="ActualWidth"/>
<Binding ElementName="RemainingTimeDisplay" Path="ActualHeight"/>
</MultiBinding>
</StackPanel.Margin>
<TextBlock FontFamily="Roboto" VerticalAlignment="Top">
<TextBlock FontSize="360" Text="{Binding RemainingTime.Minutes, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay, UpdateSourceTrigger=PropertyChanged, StringFormat=D2, Converter={StaticResource IntAbsConverter}}"/>
<TextBlock FontSize="128" Text="{Binding RemainingTime.Seconds, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay, UpdateSourceTrigger=PropertyChanged, StringFormat=D2, Converter={StaticResource IntAbsConverter}}"/>
</TextBlock>
</StackPanel>
</Canvas>
I tried also some more things, that I don't repeat here in code. I tried using "run" as a child of on single TextBlock for both text elements and I (actually started) tried without the TextBlock that encloses the other two.
So I tried a lot, I googled a lot - and I'm still not where I want to be.
Any hint would be really appreciated!
Thanks,
Marcus
Try the following:
<TextBlock FontSize="360"
Text="00"
LineHeight="360"
LineStackingStrategy="BlockLineHeight" />
<TextBlock FontSize="128"
LineHeight="360"
LineStackingStrategy="BlockLineHeight">
<Run Text="00" BaselineAlignment="Top" />
</TextBlock>

WPF Datagrid Column Visibility not working with MultiBinding

I am trying to control the visibility of a DataGridTextColumn using two Boolean values. One of the values is being set by a combo box and I am able to see in the debugger that Boolean values are being properly handled by the booleanAllTrueConverter.
My problem is that the converter value being returned has no effect on the column visibility. The column is always visible even when FALSE is returned from the converter.
I would certainly appreciate any ideas that are offered.
Thanks.
<DataGrid
Name="myDataGrid"
ItemsSource="{Binding Source={StaticResource ZZZZ}}"
AutoGenerateColumns="False"
IsReadOnly="True"
KeyboardNavigation.TabNavigation="None"
>
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding SomeItems}" >
<DataGridTextColumn.Visibility>
<MultiBinding Converter="{StaticResource booleanAllTrueConverter}">
<Binding
Source="{StaticResource ProxyElement}"
Path="DataContext.IsBlahVisible"
Mode="TwoWay"
UpdateSourceTrigger="PropertyChanged"
/>
<Binding
Source="{StaticResource ProxyElement}"
Path="DataContext.AreColumnsVisible"
Mode="TwoWay"
UpdateSourceTrigger="PropertyChanged"
/>
</MultiBinding>
</DataGridTextColumn.Visibility>
<DataGridTextColumn.HeaderTemplate>
<DataTemplate>
<Grid HorizontalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="40"/>
</Grid.ColumnDefinitions>
<local:ComboBox
Grid.Column="0"
Width="22"
Height="36"
HorizontalAlignment="Right"
VerticalAlignment="Center"
ItemsSource="{Binding DataContext.SomeItems, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"
SelectedItems="{Binding DataContext.SelectedSomeItem, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"
></local:ComboBox>
<TextBlock
Text="SomeItems"
Grid.Column="1"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Grid.ColumnSpan="2"
Height="16"
Margin="0,3"
Width="37"
/>
</Grid>
</DataTemplate>
</DataGridTextColumn.HeaderTemplate>
</DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
You need to return either Visibility.Visible instead of true or return Visibility.Collapsed instead of false from booleanAllTrueConverter

Binding gives UnsetValue on multiple binding

I have a datagrid which gets its data out of a datatable like
Inside if there is a textbox with a contextmenu and this contextmenu has a converter (with multibinding)
The problem is i datatable the binded data has 1 or 0 as data but in the converter i get UnsetValue.
This is the xaml code:
<DataGrid AutoGenerateColumns="False" HorizontalAlignment="Stretch" VirtualizingStackPanel.VirtualizationMode="Recycling" VirtualizingStackPanel.IsVirtualizing="True" Margin="0,1,0,0" x:Name="TrackingDataGrid" IsReadOnly="True" CanUserAddRows="False" CanUserDeleteRows="False" IsManipulationEnabled="True" CanUserResizeColumns="False" ItemsSource="{Binding TrackingTable}" ColumnHeaderStyle="{DynamicResource dataGridColumnStyle}" Style="{DynamicResource dataGridStyle}" EnableColumnVirtualization="True" IsEnabled="True" BorderThickness="0" CellStyle="{DynamicResource CellStyleBase}" VerticalGridLinesBrush="#FFA0A7AD" RowHeight="30" MinRowHeight="20" GridLinesVisibility="None" SelectionMode="Single" Grid.Row="1" Grid.ColumnSpan="10" Panel.ZIndex="4" MinHeight="30" Loaded="TrackingDataGrid_Loaded" CanUserReorderColumns="False" VerticalScrollBarVisibility="Disabled" ScrollViewer.CanContentScroll="True">
<DataGrid.Columns>
<DataGridTemplateColumn Header="Process Time" IsReadOnly="True" Width="100">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding DeliveryDate}" TextTrimming="CharacterEllipsis" >
<TextBlock.ContextMenu>
<ContextMenu>
<MenuItem x:Name="StandbyProcessMenuITem" Header="StandBy Process" Click="StandbyProcessMenuITem_Click" >
<!--<MenuItem.Visibility>
<MultiBinding Converter="{StaticResource RowUndoButtonVisibility}">
<Binding Path="ProductIsStandby" />
<Binding Path="ProductIsDone" />
</MultiBinding>
</MenuItem.Visibility>-->
</MenuItem>
<MenuItem x:Name="UndoProcessMenuITem" Header="Undo Process" Click="UndoProcessMenuITem_Click" >
<MenuItem.Visibility>
<MultiBinding Converter="{StaticResource RowUndoButtonVisibility}">
<Binding Path="{Binding ProductIsStandby}" />
<Binding Path="{Binding ProductIsDone}" />
</MultiBinding>
</MenuItem.Visibility>
</MenuItem>
<MenuItem x:Name="FinishProcessMenuITem" Header="Finish Process" Click="FinishProcessMenuITem_Click">
</MenuItem>
</ContextMenu>
</TextBlock.ContextMenu>
</TextBlock>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
The DataContext of a MenuItem is not the same as the DataContext of the CellTemplate but you could use a RelativeSource to bind to the PlacementTarget of the ContextMenu:
<MenuItem x:Name="UndoProcessMenuITem" Header="Undo Process" Click="UndoProcessMenuITem_Click" >
<MenuItem.Visibility>
<MultiBinding Converter="{StaticResource RowUndoButtonVisibility}">
<Binding Path="{Binding PlacementTarget.DataContext.ProductIsStandby, RelativeSource={RelativeSource AncestorType=ContextMenu}}" />
<Binding Path="{Binding PlacementTarget.DataContext.ProductIsDone, RelativeSource={RelativeSource AncestorType=ContextMenu}}" />
</MultiBinding>
</MenuItem.Visibility>
</MenuItem>

SelectedItem changes textblock variables

I want to get all the data from an Object used as ObservableCollection in a ListView. The ListView is working properly I want to when the Item is selected the information in a TextBlock (outside the ListView) to update with the info that the object as.
How can I do it? What I'm doing wrong?
So to the code:
<ListView
x:Name="dataGrid"
ItemsSource="{Binding Friends}"
Height="586"
BorderThickness="0"
SelectedItem="{Binding SelectedItemFriends,Mode=TwoWay}"
HorizontalAlignment="Left" Width="460">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Source="Resources\Images\ic_status.png" Height="24" Width="18"/>
<StackPanel Margin="5" Orientation="Vertical">
<TextBlock FontWeight="Bold" Text="{Binding name}"/>
<StackPanel x:Name="RemoveItems" Margin="5" Orientation="Vertical">
<TextBlock Text="{Binding lastLocation, StringFormat='Location: {0}'}"/>
<TextBlock Text="{Binding timestamp}"/>
</StackPanel>
</StackPanel>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<StackPanel x:Name="AdditionItems" Margin="5" Orientation="Vertical" Visibility="Visible">
<TextBlock>
<TextBlock.Text>
<MultiBinding Converter="{StaticResource myConverter}">
<Binding ElementName="dataGrid" Path="loc.country"/>
<Binding ElementName="dataGrid" Path="loc.area"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
</StackPanel>
You should specify SelectedItem property in your binding:
<TextBlock>
<TextBlock.Text>
<MultiBinding Converter="{StaticResource myConverter}">
<Binding ElementName="dataGrid" Path="SelectedItem.loc.country"/>
<Binding ElementName="dataGrid" Path="SelectedItem.loc.area"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>

MultiBinding and ContentPresenter

This is my code of ContentPresenter:
<ListBox ItemsSource="{Binding Items}" BorderThickness="0" HorizontalContentAlignment="Stretch">
<ListBox.ItemTemplate>
<DataTemplate>
<ContentPresenter x:Name="PART_ValueContainer">
<ContentPresenter.Content>
<MultiBinding>
<Binding Path="Value"/>
<Binding Path="ReadOnly"/>
</MultiBinding>
</ContentPresenter.Content>
<ContentPresenter.Resources>
<DataTemplate>
<TextBox IsReadOnly="{Binding Path=Content.ReadOnly, RelativeSource={RelativeSource AncestorType={x:Type ContentPresenter}}}"
Text="{Binding Path=Content.Value, RelativeSource={RelativeSource AncestorType={x:Type ContentPresenter}}}"
TextAlignment="Left"/>
</DataTemplate>
</ContentPresenter.Resources>
</ContentPresenter>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
I trying to fill the Text from object Items.Value and property IsReadOnly from Items.ReadOnly.
It doesn't work, I know that is not good solution, but, how to make something like that?

Categories

Resources