Skip to content

Styles are not updated while binding the DataGrid column’s HeaderTemplate and HeaderStyle using DynamicResource #11527

@SenthilkumarSF4640

Description

@SenthilkumarSF4640

Description

When assigning a DataGrid column's HeaderTemplate or HeaderStyle with {DynamicResource ...}, the header is not displayed/styled.

<DataGrid  x:Name="msDataGrid2" Grid.Column="1" Grid.Row="1" ItemsSource="{Binding Orders}" AutoGenerateColumns="False">
    <DataGrid.Columns>
        <!--DynamicResource-->
        <DataGridTextColumn Binding="{Binding OrderID}" Header="Order ID" HeaderStyle="{ DynamicResource headerStyle}"/>
        <DataGridTextColumn Binding="{Binding CustomerID}"  HeaderTemplate="{DynamicResource headerTemplate}"/>
    </DataGrid.Columns>
</DataGrid>

Note:
The same templates/styles work correctly when referenced with {StaticResource ...}.

<DataGrid  x:Name="msDataGrid1" Grid.Row="1" Grid.Column="0" ItemsSource="{Binding Orders}" AutoGenerateColumns="False">
    <DataGrid.Columns>
        <!--StaticResource-->
        <DataGridTextColumn Binding="{Binding OrderID}" Header="Order ID" HeaderStyle="{ StaticResource headerStyle}"/>
        <DataGridTextColumn Binding="{Binding CustomerID}"  HeaderTemplate="{StaticResource headerTemplate}"/>
    </DataGrid.Columns>
</DataGrid>

Please refer the Screenshot for your reference

Image

Reproduction Steps

  1. Run the sample and observe the headers of the two DataGrid columns.
  2. The column that uses StaticResource displays the expected header style and template, whereas the column that uses DynamicResource appears unstyled and shows a blank header.

Expected behavior

The DynamicResource-referenced column header should rendered/styled correctly.

Actual behavior

The DynamicResource-referenced column header is not rendered/styled correctly.

Regression?

No response

Known Workarounds

No response

Impact

No response

Configuration

No response

Other information

I have attached the sample for your reference.

DataGrid.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions