我正在尝试使用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>
答案 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()