Change Datagrid Column Foreground Programatically
C# WPF VS2017
I have several theme buttons that change all the text/button and element colors based on whichever you choose. I have everything working except for the Datagrid Headers, they do not change. The Datagrid IsSelected changes fine. I am sure it is something simple I am missing but I cannot figure it out.
This is how I added it in XAML. (Most of the text content uses Brush1, so I know it works)
<DataGrid.ColumnHeaderStyle> <Style TargetType="{x:Type DataGridColumnHeader}"> <Setter Property="Background" Value="{StaticResource PrimaryBrush}" /> <Setter Property="Foreground" Value="{StaticResource Brush1}" /> <Setter Property="HorizontalContentAlignment" Value="Center" /> <Setter Property="VerticalContentAlignment" Value="Center" /> </Style> </DataGrid.ColumnHeaderStyle>
Here is how I declared it in the App.XAML
<SolidColorBrush x:Key="Brush1" Color="{DynamicResource ResourceKey=Color1}" />
This is what one of the theme change buttons do.
private void color_blue_MouseUp(object sender, MouseButtonEventArgs e) { ///Changes the Main font Color Scheme SolidColorBrush YourBrush = Brushes.DodgerBlue; Application.Current.Resources["TemplateFont"] = YourBrush; Application.Current.Resources["NameCellStyle"] = YourBrush; Application.Current.Resources["CellStyleLeft"] = YourBrush; Application.Current.Resources["ColumnCell"] = YourBrush; ///Changes the Button Background Color var brush1 = App.Current.Resources["Brush1"]; ((SolidColorBrush)brush1).Color = Colors.DodgerBlue;
0 comments:
Post a Comment