title: How to change header and element foreground for a data grid in WPF
body: <p>As I shown in bellow I have a Datagrid and  I want to change its foreground for both header style and element style Dynamically</p>
  <pre><code>var brush1 = FindResource(&quot;DgColumnElementForeground&quot;) as SolidColorBrush;
                  if (brush1.IsFrozen) brush1 = brush1.Clone();
                  brush1.Color = (Color)ColorConverter.ConvertFromString(Default.dgContentFontColor);
  
                  var brush2 = FindResource(&quot;DgColumnHeaderForeground&quot;) as SolidColorBrush;
                  if (brush2.IsFrozen) brush2 = brush2.Clone();
                  brush2.Color = (Color)ColorConverter.ConvertFromString(Default.dgHeaderFontColor);
  </code></pre>
  <p>I used above code to get wanted result; but it didn't change anything.
  Please, tell me what's wrong with my code.
  thanks</p>
  <pre><code>&lt;DataGrid x:Name=&quot;DgArchive&quot; AutoGenerateColumns=&quot;False&quot; FlowDirection=&quot;RightToLeft&quot; HorizontalAlignment=&quot;Left&quot; KeyDown=&quot;DgArchive_OnKeyDown&quot;
                    Height=&quot;451&quot; Margin=&quot;11,74,0,0&quot; VerticalAlignment=&quot;Top&quot; Width=&quot;1167&quot; IsReadOnly=&quot;True&quot; MouseDoubleClick=&quot;DgArchive_OnMouseDoubleClick&quot;&gt;
              &lt;DataGrid.Columns&gt;
                  &lt;DataGridTextColumn Header=&quot;ID&quot; Binding=&quot;{Binding ArchiveID}&quot; FontSize=&quot;14&quot; FontFamily=&quot;Calibri&quot;
                                      MaxWidth=&quot;0&quot; /&gt;
                  &lt;DataGridTextColumn Header=&quot;کۆد&quot; Binding=&quot;{Binding ArchiveCode}&quot; Width=&quot;Auto&quot;&gt;
                      &lt;DataGridTextColumn.HeaderStyle&gt;
                          &lt;Style TargetType=&quot;{x:Type DataGridColumnHeader}&quot;&gt;
                              &lt;Setter Property=&quot;FontFamily&quot; Value=&quot;Calibri&quot; /&gt;
                              &lt;Setter Property=&quot;FontSize&quot; Value=&quot;16&quot; /&gt;
                              &lt;Setter Property=&quot;FontWeight&quot; Value=&quot;Bold&quot; /&gt;
                              &lt;Setter Property=&quot;HorizontalContentAlignment&quot; Value=&quot;Center&quot; /&gt;
                              &lt;Setter Property=&quot;Foreground&quot; Value=&quot;{DynamicResource DgColumnHeaderForeground}&quot; /&gt;
                          &lt;/Style&gt;
                      &lt;/DataGridTextColumn.HeaderStyle&gt;
                      &lt;DataGridTextColumn.ElementStyle&gt;
                          &lt;Style TargetType=&quot;{x:Type TextBlock}&quot;&gt;
                              &lt;Setter Property=&quot;FontFamily&quot; Value=&quot;Calibri&quot; /&gt;
                              &lt;Setter Property=&quot;FontSize&quot; Value=&quot;14&quot; /&gt;
                              &lt;Setter Property=&quot;HorizontalAlignment&quot; Value=&quot;Center&quot; /&gt;
                              &lt;Setter Property=&quot;Foreground&quot; Value=&quot;{DynamicResource DgColumnElementForeground}&quot; /&gt;
                          &lt;/Style&gt;
                      &lt;/DataGridTextColumn.ElementStyle&gt;
                  &lt;/DataGridTextColumn&gt;
  
                  &lt;DataGridTextColumn Header=&quot;رێکەوت&quot; Binding=&quot;{Binding ArchiveDate, StringFormat=\{0:dd.MM.yyyy\}}&quot; Width=&quot;Auto&quot;&gt;
                      &lt;DataGridTextColumn.HeaderStyle&gt;
                          &lt;Style TargetType=&quot;{x:Type DataGridColumnHeader}&quot;&gt;
                              &lt;Setter Property=&quot;FontFamily&quot; Value=&quot;Calibri&quot; /&gt;
                              &lt;Setter Property=&quot;FontSize&quot; Value=&quot;16&quot; /&gt;
                              &lt;Setter Property=&quot;FontWeight&quot; Value=&quot;Bold&quot; /&gt;
                              &lt;Setter Property=&quot;HorizontalContentAlignment&quot; Value=&quot;Center&quot; /&gt;
                              &lt;Setter Property=&quot;Foreground&quot; Value=&quot;{DynamicResource DgColumnHeaderForeground}&quot; /&gt;
                          &lt;/Style&gt;
                      &lt;/DataGridTextColumn.HeaderStyle&gt;
                      &lt;DataGridTextColumn.ElementStyle&gt;
                          &lt;Style TargetType=&quot;{x:Type TextBlock}&quot;&gt;
                              &lt;Setter Property=&quot;FontFamily&quot; Value=&quot;Calibri&quot; /&gt;
                              &lt;Setter Property=&quot;FontSize&quot; Value=&quot;16&quot; /&gt;
                              &lt;Setter Property=&quot;HorizontalAlignment&quot; Value=&quot;Center&quot; /&gt;
                              &lt;Setter Property=&quot;Foreground&quot; Value=&quot;{DynamicResource DgColumnElementForeground}&quot; /&gt;
                          &lt;/Style&gt;
                      &lt;/DataGridTextColumn.ElementStyle&gt;
                  &lt;/DataGridTextColumn&gt;
  &lt;/DataGrid&gt;
  
  </code></pre>