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

xaml

(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 :

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

(It Soft) #2

Add this resource to your DataGrid:

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