使用MahApps.Metro为Listbox交替行颜色

时间:2015-07-22 15:48:07

标签: .net wpf listbox mahapps.metro alternating

我正在尝试使用MahApps.Metro项目为WPF中的列表框创建交替行颜色。当我添加样式和触发器时,所有项目的背景仍为白色:

        <Style TargetType="ListBox">
            <Setter Property="AlternationCount" Value="2" />
            <Style.Triggers>
                <Trigger Property="ItemsControl.AlternationIndex" Value="1">
                    <Setter Property="Background" Value="Blue" />
                </Trigger>
            </Style.Triggers>
        </Style>

1 个答案:

答案 0 :(得分:1)

Style而不是ListBoxItem上应用ListBox,如下所示:

<ListBox AlternationCount="2">
    <ListBox.Resources>
        <Style TargetType="ListBoxItem">
            <Style.Triggers>
                <Trigger Property="ItemsControl.AlternationIndex" Value="1">
                    <Setter Property="Background" Value="Blue" />
                </Trigger>
            </Style.Triggers>
        </Style>
    </ListBox.Resources>
</ListBox>

请勿忘记将AlternationCount添加到ListBox,因为Style

中已不再设置sourceCpp()