Search code examples
c#wpfxamlsystemcolors

How to change the SystemColors of a DataGrid app wide


I know how to change a SystemColor for a specific UIElement like this

<DataGrid>
  <DataGrid.Resources>
    <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="LightGray" />
  </DataGrid.Resources>
</DataGrid>

But I want to make this setting for all DataGrids in my app. How can I set this up in my app.xaml file to make it work? This obviously does not work:

<Style TargetType="{x:Type DataGrid}">
  <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="LightGray" />
</Style>

Solution

  • Put it in the resources of the Style:

    <Style TargetType="DataGrid">
        <Style.Resources>
            <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="LightGray" />
        </Style.Resources>
    </Style>