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
Some of the reason which I experienced the row selected event not working
This is what helped me. Setting the Style for DataGridCell
<Style TargetType="{x:Type DataGridCell}">
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="Green"/>
<Setter Property="Foreground" Value="White"/>
</Trigger>
</Style.Triggers>
</Style>
And since I was using a template column with a label inside, I bound the Foreground property to the container Foreground using RelativeSource binding:
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Label Content="{Binding CategoryName,
Mode=TwoWay,
UpdateSourceTrigger=LostFocus}"
Foreground="{Binding Foreground,
RelativeSource={RelativeSource Mode=FindAncestor,
AncestorLevel=1,
AncestorType={x:Type DataGridCell}}}"
Width="150"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
Got it. Add the following within the DataGrid.Resources section:
<DataGrid.Resources>
<Style TargetType="{x:Type dg:DataGridCell}">
<Style.Triggers>
<Trigger Property="dg:DataGridCell.IsSelected" Value="True">
<Setter Property="Background" Value="#CCDAFF" />
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.Resources>