I have a DataGrid
that uses AlternatingRowBackground
to make itself easier to read. In that same grid I also have a background color change for rows based on a "IsMouseOver"
Setter Property
in my App.xaml
file. The problem that I am having is that the rows that have the alternating color (they are not white), do not change to the "IsMouseOver"
color when the mouse hovers over it. Basically the AlternatingRowBackground
color is taking precedence over my RowStyle
. How do I make it so that the colored rows change as well when the mouse hovers over them?
App.xaml:
<!-- DataGrid Row Style -->
<Style x:Key="RowStyleWithAlternation" TargetType="DataGridRow">
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="Background" Value="GhostWhite"/>
<Setter Property="FontWeight" Value="Normal"/>
<Setter Property="ContextMenu" Value="{x:Null}"/>
<Style.Triggers>
<Trigger Property="AlternationIndex" Value="1">
<Setter Property="Background" Value="#FFD0D0E0"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="Purple"/>
</Trigger>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="#F9F99F" />
</Trigger>
</Style.Triggers>
</Style>
User Control xaml:
<DataGrid ... AlternatingRowBackground="Gray" RowStyle="{StaticResource RowStyleWithAlternation}" ... />
It works if you change your UserControl.xaml as follows:
<DataGrid RowStyle="{StaticResource RowStyleWithAlternation}" AlternationCount="2" />
The background is set through the AlternationIndex Trigger on your row which takes no priority over the IsMouseOver.
I've found the answer on this post:
WPF Style Trigger for DataGridRow Background Color Trumped by AlternatingRowBackground Brush
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