Unable to override DataGridColumHeader template

Sep 8, 2014 at 11:15 AM
First thank's for a great UI Framework it has thought me a lot about styling and resource organisation.

I need to create a read-only datagrid without row highlight and a header row without any manipulation. Basically a dead grid. I have posted a question on stackoverflow that describes the problem but I will summarize it here.
<Style x:Key="BilagsColumnHeaderStyle" TargetType="{x:Type DataGridColumnHeader}">
    <Setter Property="FontSize" Value="12"/>
    <Setter Property="FontWeight" Value="SemiBold"/>
    <Setter Property="HorizontalAlignment" Value="Left"/>
    <Setter Property="Background" Value="Transparent"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type DataGridColumnHeader}">
                <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
                                          SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" 
                                          VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                          Margin="4,3"/>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>
None of the styles in BilagsColumnHeaderStyle are applied. Only styles defined in the Asserts/DataGrid.xaml/Style x:Key="{x:Type DataGridColumnHeader}" are applied. If I put the BilagsColumnHeaderStyle directly on the DataGrid then it works. Why can't I override the ColumnHeaderStyle?
 <Style x:Key="BilagDatagridStyle" TargetType="{x:Type DataGrid}" BasedOn="{StaticResource DefaultReadOnlyGridStyle}">
        <Setter Property="CellStyle" Value="{StaticResource DataGridCellNoInteractionStyle}"/>
        <Setter Property="RowStyle" Value="{StaticResource DataGridRowNoInteractionStyle}"/>
        <Setter Property="ColumnHeaderStyle" Value="{StaticResource BilagsColumnHeaderStyle}"/>
    </Style>
Sep 8, 2014 at 5:30 PM
This works just fine for me:
        <Style x:Key="headerStyle"
               BasedOn="{StaticResource {x:Type DataGridColumnHeader}}"
               TargetType="{x:Type DataGridColumnHeader}">
            <Setter Property="TextBlock.Foreground" Value="{DynamicResource Accent}" />
            <Setter Property="TextBlock.FontWeight" Value="Normal" />
            <Setter Property="HorizontalContentAlignment" Value="Stretch" />
        </Style>
and then in my DataGrid.Columns
<DataGridTextColumn Width="Auto"
                    Binding="{Binding EWP}"
                    Header="ewp"
                    HeaderStyle="{StaticResource headerStyle}">

    <DataGridTextColumn.HeaderTemplate>
        <DataTemplate>
            <Grid x:Name="grd">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>

                <TextBlock Foreground="{DynamicResource Accent}" Text="ewp" />

                <mui:ModernButton x:Name="filterBtn"
                                  Grid.Column="1"
                                  Margin="10,0,0,0"
                                  Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.DisplayEWPPopupCommand}"
                                  CommandParameter="{Binding}"
                                  EllipseStrokeThickness="0"/>                                
blah blah
Sep 8, 2014 at 5:44 PM
Thank's, but it's not what I am after. I am trying to create a single style that I can apply to a grid like this:
<DataGrid Style="{StaticResource BilagDatagridStyle}">

<Style x:Key="BilagDatagridStyle" TargetType="{x:Type DataGrid}" BasedOn="{StaticResource DefaultReadOnlyGridStyle}">
        <Setter Property="CellStyle" Value="{StaticResource DataGridCellNoInteractionStyle}"/>
        <Setter Property="RowStyle" Value="{StaticResource DataGridRowNoInteractionStyle}"/>
        <Setter Property="ColumnHeaderStyle" Value="{StaticResource BilagsColumnHeaderStyle}"/>
        <Setter Property="RowHeaderStyle" Value="{DynamicResource DataGridRowHeaderStyle}"/>
    </Style>
Does it make sense?