2
如何为WPF ListView设置备用行颜色。 如果我只有一个列表,我可以在XAML中设置,但在我的情况下,需要根据列表更改备用行颜色。 例如,我有3名差异列表...
1)为了用公司名称,
2)为了按行业
3)为了按市场价值
每个列表应该有自己的备用行颜色。
我怎样才能做到这一点(在C#或XAML文件)。任何意见/建议,将aprreciatedWPF列表查看3个不同列表的不同交替行颜色..?
如何为WPF ListView设置备用行颜色。 如果我只有一个列表,我可以在XAML中设置,但在我的情况下,需要根据列表更改备用行颜色。 例如,我有3名差异列表...
1)为了用公司名称,
2)为了按行业
3)为了按市场价值
每个列表应该有自己的备用行颜色。
我怎样才能做到这一点(在C#或XAML文件)。任何意见/建议,将aprreciatedWPF列表查看3个不同列表的不同交替行颜色..?
这应该工作,不管你做什么的清单,因为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>
代码隐藏测试修改项目:
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
如果你的意思,你想要一个不同的R ow颜色使用取决于排序然后我想你会想要使用MultiTrigger代替,其中一个触发属性是交替索引和一个属性连接到一个属性,指示正在使用什么类型。 – 2010-11-28 01:45:11