【问题标题】:Datagrid hover not working with alternate row colors - wpfDatagrid悬停不适用于备用行颜色 - wpf
【发布时间】:2011-06-20 17:26:20
【问题描述】:

这适用于 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>

【问题讨论】:

    标签: wpf datagrid wpf-controls wpfdatagrid


    【解决方案1】:

    样式的顺序很重要。

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

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

    【讨论】:

    • 但这行得通,&lt;Style TargetType="DataGrid" BasedOn="{StaticResource {x:Type DataGrid}}"&gt; &lt;Setter Property="AlternatingRowBackground" Value="#FF282828"/&gt; &lt;/Style&gt;
    猜你喜欢
    • 2012-02-12
    • 2013-11-22
    • 2017-06-16
    • 2016-05-03
    • 2020-01-10
    • 2012-06-04
    • 1970-01-01
    • 1970-01-01
    • 2011-01-30
    相关资源
    最近更新 更多