Datagrid鼠标悬停在交替行颜色时无法工作 - wpf

4

这对于DataGridRow来说非常有效。

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

但是当我添加这些内容后,鼠标悬停样式不起作用了。
<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>
1个回答

7

样式的顺序很重要。

在应用其他触发器之前应用交替触发器可以起作用。

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

3
但是这个有效,<Style TargetType="DataGrid" BasedOn="{StaticResource {x:Type DataGrid}}"> <Setter Property="AlternatingRowBackground" Value="#FF282828"/> </Style> - Abin

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接