How To Change the Color of a Selected Line in WPF DataGrid?


(isoftech) #1

Hello, I started with WPF ( XAML ) and I was desperately trying to change the color of a selected line in my DataGrid. I create a resource in my grid , but I can not use :

<!-- DataGridCell Style-->
<Style x:Key="MyDataGridCellStyle" TargetType="{x:Type DataGridCell}">
<Setter Property="Background" Value="White"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="Red"/>
<Setter Property="Foreground" Value="White"/>

(It Soft) #2

Add this resource to your DataGrid:

  <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}"