'Why doesn't Header binding DynamicResource work?
Why doesn't Header binding DynamicResource work?
<DataGridTextColumn Binding="{Binding CustomerID}" Header="{DynamicResource firstName}" />
code environment:
App.xmal:
<Application.Resources>
<System:String x:Key="firstName" >Before Change Name</System:String>
<System:String x:Key="secondName" >After Change Name</System:String>
</Application.Resources>
MainWindow.xaml:
<Window.DataContext>
<local:ViewModel/>
</Window.DataContext>
<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}" />
</DataGrid.Columns>
</DataGrid>
<StackPanel Grid.Column="1">
<Button x:Name="btn" Content="Change Resource" Width="150" Height="30" Click="OnChangeResourceClicked"/>
</StackPanel>
</Grid>
Click Method:
private void OnChangeResourceClicked(object sender, RoutedEventArgs e)
{
App.Current.Resources["firstName"] = App.Current.Resources["secondName"];
}
Result after clicking the button:
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|

