Witam
Chciałbym zmienić mojego Datagrida aby nagłówki kolumn miały dwa pola tekstowe w sobie. Stworzyłem klasę i Depndency property : MyProperty aczkolwiek nie działa mi bindowanie do niej. Próbowałem róznych kombinacji niestety nie wiem gdzie robię błąd. Prosze o pomoc
<extensions:CustomDataGridTextColumn HeaderStyle="{StaticResource Nagłówek2tb}" Header="Nagłówek 1" MyProperty ="Nagłówek2"/>
Styl nagłówka
<Style TargetType="{x:Type DataGridColumnHeader}" x:Key="Nagłówek2tb">
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate >
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Text="{Binding}" TextWrapping="Wrap"/>
<TextBlock Grid.Row="1" Text="{Binding MyProperty, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=DataGridTextColumn}}"/>
</Grid>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
Klasa
public class CustomDataGridTextColumn : System.Windows.Controls.DataGridTextColumn
{
public string MyProperty
{
get { return (string)GetValue(MyPropertyProperty); }
set { SetValue(MyPropertyProperty, value); }
}
public static readonly DependencyProperty MyPropertyProperty =
DependencyProperty.Register("MyProperty", typeof(string), typeof(CustomDataGridTextColumn), new UIPropertyMetadata(""));
}