WPF Listview 3个差异列表的不同交替行颜色..?

raj*_*raj 2 wpf listview row colors alternate

如何为WPF Listview设置备用行颜色.如果我只有1个列表,我可以在XAML中设置,但在我的情况下,需要根据列表更改备用行颜色.例如,我有3个差异列表...
1)按公司名称排序,
2)按部门
排序3)按市场价值排序
每个列表应该有自己的备用行颜色.
我该怎么做(在C#或XAML文件中).任何想法/建议都会受到重视

J C*_*per 6

无论你对列表做什么都应该这样做,因为ItemsControl.AlternationIndex是一个依赖属性,应该更新:

<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApplication1"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
    <Style TargetType="ListBoxItem">
        <Style.Triggers>
            <Trigger Property="ItemsControl.AlternationIndex"  Value="0">
                <Setter Property="Background" Value="AliceBlue" />
            </Trigger>
        </Style.Triggers>
    </Style>
</Window.Resources>
<StackPanel>  
    <ListBox Name="bob" AlternationCount="2">
        <ListBoxItem Content="Herald"/>
        <ListBoxItem Content="Kumar" />
        <ListBoxItem Content="Bill" />
        <ListBoxItem Content="Dudley" />
        <ListBoxItem Content="Jack" />
    </ListBox>
    <Button Click="Button_Click">boo</Button>
</StackPanel>
Run Code Online (Sandbox Code Playgroud)

Code Behind测试对项目的更改:

Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
    Dim item1 As ListBoxItem = bob.Items(4)
    bob.Items.Remove(item1)
    bob.Items.Insert(0, item1)
End Sub
Run Code Online (Sandbox Code Playgroud)