I have a data grid in my WPF project and this my Xaml and c# codes, why can't I change its foreground for column header style and element style? does anybody know where is wrong with my code? I have several data grid in my project and I use the same codes for all of them without any change but in some data grids it works for both column header style and element style or just for column header style either column element style only and in the rest it doesn't work for any of them.
<Window.Resources>
<SolidColorBrush x:Key="DgColumnHeaderForeground" Color="Black"/>
<SolidColorBrush x:Key="DgColumnElementForeground" Color="Black"/>
</Window.Resources>
<Grid>
<DataGrid x:Name="DgSuggestion" AutoGenerateColumns="False" FlowDirection="RightToLeft" HorizontalAlignment="Left"
Height="326" Margin="10,158,0,0" VerticalAlignment="Top" Width="662" IsReadOnly="True">
<DataGrid.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="#7FEEE30E" />
</DataGrid.Resources>
<DataGrid.VerticalGridLinesBrush>
<SolidColorBrush Color="#FFBDB0B0" Opacity="0.7" />
</DataGrid.VerticalGridLinesBrush>
<DataGrid.HorizontalGridLinesBrush>
<SolidColorBrush Color="#FFBDB0B0" Opacity="0.7" />
</DataGrid.HorizontalGridLinesBrush>
<DataGrid.Columns>
<DataGridTextColumn Header="ID" Binding="{Binding SuggestionID}" FontSize="14" FontFamily="Calibri" MaxWidth="0" />
<DataGridTextColumn Header="Date" Binding="{Binding SuggestionRequestDate, StringFormat=\{0:dd.MM.yyyy\}}" Width="Auto">
<DataGridTextColumn.HeaderStyle>
<Style TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="FontFamily" Value="Calibri" />
<Setter Property="FontSize" Value="16" />
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="Foreground" Value="{DynamicResource DgColumnHeaderForeground}" />
</Style>
</DataGridTextColumn.HeaderStyle>
<DataGridTextColumn.ElementStyle>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="FontFamily" Value="Calibri" />
<Setter Property="FontSize" Value="14" />
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="HorizontalAlignment" Value="Center" />
<Setter Property="Foreground" Value="{DynamicResource DgColumnElementForeground}" />
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
<DataGridTextColumn Header="Dept" Binding="{Binding SuggestionDept}" Width="Auto">
<DataGridTextColumn.HeaderStyle>
<Style TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="FontFamily" Value="Calibri" />
<Setter Property="FontSize" Value="16" />
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="Foreground" Value="{DynamicResource DgColumnHeaderForeground}" />
</Style>
</DataGridTextColumn.HeaderStyle>
<DataGridTextColumn.ElementStyle>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="FontFamily" Value="Calibri" />
<Setter Property="FontSize" Value="14" />
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="HorizontalAlignment" Value="Center" />
<Setter Property="Foreground" Value="{DynamicResource DgColumnElementForeground}" />
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
</Grid>
And this is my code behind
private void WinAppearanceMethod()
{
var brush5 = FindResource("DgColumnElementForeground") as SolidColorBrush;
if (brush5.IsFrozen) brush5 = brush5.Clone();
if (!string.IsNullOrEmpty(Default.dgContentFontColor)) brush5.Color = (Color)ColorConverter.ConvertFromString(Default.dgContentFontColor);
var brush6 = FindResource("DgColumnHeaderForeground") as SolidColorBrush;
if (brush6.IsFrozen) brush6 = brush6.Clone();
if (!string.IsNullOrEmpty(Default.dgHeaderFontColor)) brush6.Color = (Color)ColorConverter.ConvertFromString(Default.dgHeaderFontColor);
}