Overriding DataGridColumnHeader Style

Jan 31, 2009 at 5:01 PM
Hi,

I am trying to create "MyDataGrid" which is derived from the WPF DataGrid. I am able to modify the ControlTemplate for the DataGrid itself in Generic.xaml:

<Style x:Key="{x:Type local:MyDataGrid}" TargetType="{x:Type local:MyDataGrid}">
<Setter Property="Background"...

static MyDataGrid()
{
    DefaultStyleKeyProperty.OverrideMetadata(
        typeof(MyDataGrid),
        new FrameworkPropertyMetadata(typeof(MyDataGrid)));

//     DefaultStyleKeyProperty.OverrideMetadata(
//         typeof(DataGridColumnHeader),
//         new FrameworkPropertyMetadata(typeof(DataGridColumnHeader)));
}

but I don't seem to be able to apply changes to the DataGridColumnHeader in Generic.xaml. I have worked around the problem by putting my changes to DataGridColumnHeader in another resource dictionary and loading that in the DataGrid constructor, but I would really have liked to have kept the changes to Generic.xaml (and also understand better why the changes I make there won't work).

Can anyone shed any light on this for me please?

Thanks
Feb 1, 2009 at 9:46 PM
Fixed - it seems I was trying to make it more complicated than it is! All that needed to be done was to apply a style to the DataGridColumnHeader in the DataGrid style, in Generic.xaml:

 

 

<Style x:Key="{x:Type local:MyDataGrid}" TargetType="{x:Type local:MyDataGrid}">

 

 

 

<Setter Property="ColumnHeaderStyle" Value="{StaticResource MyDataGridColumnHeader}"/>