DynamicResource is not working for Header property in DataGridTextColumn
See original GitHub issue- .NET Core Version: .Net 6.0
- Does the bug reproduce also in WPF for .NET Framework 4.8?: Yes
Problem description:
I have defined the DynamicResource for Header property in DataGridTextColumn of DataGrid. Please refer the below code snippet,
<Application.Resources>
<System:String x:Key="firstName" >Before Change Name</System:String>
<System:String x:Key="secondName" >After Change Name</System:String>
</Application.Resources>
<DataGridTextColumn Binding="{Binding CustomerID}"
Header="{DynamicResource firstName}" />
When change the resource at runtime Header property does not change the value in DataGrid. Can you please check and elaborate why DynamicResource is not working in DataGridTextColumn.Header property of DataGrid?
Note : If we use HeaderTemplate property in DataGridTextColumn its working properly in DataGrid. Please refer the code snippet,
<Window.Resources>
<DataTemplate x:Key="headerTemplate">
<TextBlock Height="50"
Text="{DynamicResource firstName}"
TextWrapping="Wrap" />
</DataTemplate>
</Window.Resources>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="200" />
</Grid.ColumnDefinitions>
<DataGrid x:Name="dataGrid"
ItemsSource="{Binding Orders}"
AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding OrderID}"
HeaderTemplate="{StaticResource headerTemplate}" />
<DataGridTextColumn Binding="{Binding CustomerID}"
Header="{DynamicResource firstName}" />
<DataGridTextColumn Binding="{Binding CustomerName}" Header="Customer Name" />
<DataGridTextColumn Binding="{Binding Country}" Header="Country" />
<DataGridTextColumn Binding="{Binding UnitPrice}" Header="Unit Price" />
</DataGrid.Columns>
</DataGrid>
</Grid>
Please refer the Screenshot for your reference
Minimal repro: Step 1: Run the sample
Step 2: Click the Change resource button
Actual behavior: DynamicResource is not working for Header property in DataGridTextColumn
Expected behavior: DynamicResource is working properly for Header property in DataGridTextColumn
I have attached the sample for your reference. Sample Link: DataGrid.zip
Can you please check and provide the solution to use the DynamicResource in Header property in DataGridTextColumn?
Regards, Vijayarasan S
Issue Analytics
- State:
- Created a year ago
- Reactions:2
- Comments:7 (4 by maintainers)
Top GitHub Comments
@vijayarasan
For this one you are mixing two things together, you have to pick either of the ones mentioned below.
Either use
and
Or use
and
In this first approach we are setting style with the help of header template, and in the second one we are setting it with the help of static resource.
I hope this addresses your question, in such a case we can close it.
Hi @miloush,
The purpose of requesting the simple way to access the property that is bound for HeaderText is a very simple comparatively process with HeaderTemplate