I've got a WPF DataGrid where the SelectedItem is bound to a ViewModel property.
SelectedItem="{Binding DataContext.SelectedBooking, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"
If a user clicks on a Row, selecting it, the only visual clue is that the gray background of the row becomes very slightly lighter. I need to make this more obvious, so I tried adding these, individually:
<DataGrid.RowStyle>
<Style TargetType="{x:Type DataGridRow}">
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Foreground" Value="Red"/>
<Setter Property="Background" Value="Red" />
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.RowStyle>
And
<DataGrid.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Red"/>
</DataGrid.Resources>
The result is the same. When a user single-clicks on a row it very briefly flashes red and then goes back to pale gray, although the Row actually remains as being Selected. If they click on it a second time, it goes red and stays red.
If I remove the Binding on SelectedItem, it works as expected. How can I make this work regardless of the Binding?
I found the answer myself, scrolling through the Intellisense for SystemColors. There's an InactiveSelection brush that you can override too.
<DataGrid.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Red"/>
<SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" Color="Red"/>
</DataGrid.Resources>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With