ListBox的着色

时间:2010-10-28 06:44:56

标签: wpf xaml listbox

是否可以在WPF列表框中获取此行颜色?


浅灰色
灰色

浅灰色
等?

由于

1 个答案:

答案 0 :(得分:4)

是的,这是可能的。您可以使用ListBox的AlternationCount属性。像

这样的东西
<Style TargetType="{x:Type ListBoxItem}">
    <Style.Triggers>
        <Trigger Property="ItemsControl.AlternationIndex" Value="0">
            <Setter Property="Background" Value="White"></Setter>
        </Trigger>
        <Trigger Property="ItemsControl.AlternationIndex" Value="1">
            <Setter Property="Background" Value="LightGray"></Setter>
        </Trigger>
        <Trigger Property="ItemsControl.AlternationIndex" Value="2">
            <Setter Property="Background" Value="Gray"></Setter>
        </Trigger>
    </Style.Triggers>
</Style>

然后只需在ListBox上设置AlternationCount

<ListBox AlternationCount="3"
         ...>
相关问题