I have a usercontrol made up of a datagrid and a label. I define a DependencyProperty that should change a label and a datagrid column header of the user control. The content of the label changes according to the value of the DependencyProperty but the header of the Grid Column does not.
This is my code behind:
public static readonly DependencyProperty Testing =
DependencyProperty.Register("Testing", typeof(string), typeof(uMultipleVolume), new UIPropertyMetadata("Welcome"));
public string _Testing
{
get { return (string)GetValue(Testing); }
set { SetValue(Testing, value); }
}
and them my Xaml looks like this:
<UserControl x:Class="BAS.Company.UserControls.General.uMultipleVolume"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:commonWpf="clr-namespace:Rubenhak.Common.WPF;assembly=Rubenhak.Common.WPF"
DataContext="{Binding RelativeSource={RelativeSource self}}"
mc:Ignorable="d"
Height="Auto" Width="auto" Loaded="UserControl_Loaded" x:Name="uXamlMultipleVolume" x:Uid="uXamlMultipleVolume" >
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="29" />
<RowDefinition Height="1*" />
</Grid.RowDefinitions>
<DataGrid x:Name="dgValues" AutoGenerateColumns="False" Grid.Row="1" Margin="5,0,5,0" Width="500" ItemsSource="{Binding}" CanUserResizeColumns="False"
HeadersVisibility="Column" CanUserAddRows="False" CanUserDeleteRows="False"
CanUserReorderColumns="False" CanUserResizeRows="False" CanUserSortColumns="False" IsReadOnly="True" PreviewKeyDown="dgValues_PreviewKeyDown">
<DataGrid.Columns>
<!-- Here i was expecting to see welcome but nothing shows up not even an error -->
<DataGridTextColumn Header="{Binding ElementName=uXamlMultipleVolume , Path=Testing}" Width="80" Binding="{Binding Path=Pieces,StringFormat={}{0:0}}"
/>
</DataGrid.Columns>
</DataGrid>
<!-- Here the Label shows Welcome as it should -->
<Label Content="{Binding ElementName=uXamlMultipleVolume , Path=Testing}" Grid.RowSpan="2" Height="28" HorizontalAlignment="Left" Name="label1" VerticalAlignment="Top"
/>
</Grid>
</UserControl>
Thanks
Ivan