Datagrid hover does not work with alternate row colors - wpf

This works great with DataGridRow ..

   <Trigger Property="IsMouseOver" Value="true">
        <Setter Property="Background" Value="{StaticResource RolloverBrush}" />
        <Setter Property="Foreground" Value="#000" />
   </Trigger>

But when I add them, the styles with the mouse do not work.

<Trigger Property="ItemsControl.AlternationIndex" Value="0">
    <Setter Property="Background" Value="{StaticResource LightRowBrush0}" />
</Trigger>
<Trigger Property="ItemsControl.AlternationIndex" Value="1">
    <Setter Property="Background" Value="{StaticResource LightRowBrush1}" />
</Trigger>
+3
source share
1 answer

The order of styles matters.

Apply alternate triggers before the others work.

    <Style.Triggers>
        <Trigger Property="ItemsControl.AlternationIndex" Value="0">
            <Setter Property="Background" Value="{StaticResource LightRowBrush0}" />
        </Trigger>
        <Trigger Property="ItemsControl.AlternationIndex" Value="1">
            <Setter Property="Background" Value="{StaticResource LightRowBrush1}" />
        </Trigger>
        <Trigger Property="IsMouseOver" Value="true">
            <Setter Property="Background" Value="{StaticResource RolloverBrush}" />
            <Setter Property="Foreground" Value="#000" />
        </Trigger>
        <Trigger Property="IsSelected" Value="true">
            <Setter Property="Background" Value="{StaticResource SelectedBrush}" />
            <Setter Property="Foreground" Value="#000" />
        </Trigger>
    </Style.Triggers>
+7
source

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


All Articles