DataGrid - AlternatingRowBackground color that interferes with the IsMouseOver color

I have DataGridone that uses AlternatingRowBackgroundto make it more readable. At the same grid I also have a changing background colors for rows based on "IsMouseOver" Setter Propertyin my file App.xaml. The problem I am facing is that lines that have alternating color (they are not white) do not change color "IsMouseOver"when the mouse hangs over it. Basically, color AlternatingRowBackgroundtakes precedence over mine RowStyle. How to make colored lines change when the mouse hangs 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>

Xaml user control:

<DataGrid ... AlternatingRowBackground="Gray" RowStyle="{StaticResource RowStyleWithAlternation}" ... />
+4
source share
1

, UserControl.xaml :

<DataGrid RowStyle="{StaticResource RowStyleWithAlternation}" AlternationCount="2" />

AlternationIndex , IsMouseOver.

:

WPF DataGridRow, AlternatingRowBackground Brush

+1

Source: https://habr.com/ru/post/1568042/


All Articles