How can I set the color of a selected row in DataGrid

Jan Bannister picture Jan Bannister · Aug 3, 2009 · Viewed 144.1k times · Source

The default background color of a selected row in DataGrid is so dark that I can't read it. Is there anyway of overriding it?

Tried this

<dg:DataGrid.RowStyle>
    <Style TargetType="{x:Type dg:DataGridRow}">
        <Style.Triggers>
            <Trigger Property="IsSelected" Value="True" >
                <Setter Property="Background" Value="Gainsboro" />
            </Trigger>
        </Style.Triggers>
    </Style>
</dg:DataGrid.RowStyle>

But still nothing...

Answer

Seb Kade picture Seb Kade · Aug 6, 2010

The above solution left blue border around each cell in my case.

This is the solution that worked for me. It is very simple, just add this to your DataGrid. You can change it from a SolidColorBrush to any other brush such as linear gradient.

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