DataGrid's selected row color when inactive

white.zaz picture white.zaz · Nov 3, 2011 · Viewed 41.9k times · Source

How can I style WPF DataGrid to change the color of selected row when DataGrid lost its focus?

Answer

Steve Streeting picture Steve Streeting · Oct 24, 2012

After ages of searching, I found a surprisingly simple way to do this that's cleaner than the Got/LostFocus approach posted earlier:

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

This just sets the inactive background colour to DarkGray, leaving the active background colour to the default, but you can change that too using the SystemColors.HighlightBrushKey too of course.

The foreground resource key for inactive selections is SystemColors.InactiveSelectionHighlightTextBrushKey.