我有一个将 AlternationCount 设置为 2 的 ListView。我有一个 ListViewItem 样式,该样式当前将 ListViewItem 的背景颜色设置为交替颜色,我想添加第三个触发器,该触发器触发 ColorAnimation 以在红色和白色之间为颜色设置动画绑定 ViewModel 的一个属性为真(在本例中为一个名为“Locked”的属性)。
我遇到了这篇文章,并尝试了底部的 xaml:
http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/e7897cbd-71d9-45e6-9b17-0cd5bde5859f
但是,直到我将鼠标悬停或选择项目,然后选择或将鼠标悬停在不同的项目上,动画似乎不会触发我。我从前两个 MultiDataTriggers 中获得了交替的颜色,但是当项目添加到集合中时动画不会触发。这是我的 XAML:
<Style x:Key="alternatingListViewItemStyle" TargetType="{x:Type ListViewItem}">
<Setter Property="Background" Value="White" />
<Style.Triggers>
<MultiDataTrigger >
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=(ItemsControl.AlternationIndex)}" Value="0" />
<Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=(ListViewItem.IsSelected)}" Value="False" />
<Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=(Panel.IsMouseOver)}" Value="False" />
<Condition Binding="{Binding Locked}" Value="False" />
</MultiDataTrigger.Conditions>
<Setter Property="Background" Value="DarkGray" />
</MultiDataTrigger>
<MultiDataTrigger >
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=(ItemsControl.AlternationIndex)}" Value="1" />
<Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=(ListViewItem.IsSelected)}" Value="False" />
<Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=(Panel.IsMouseOver)}" Value="False" />
<Condition Binding="{Binding Locked}" Value="False" />
</MultiDataTrigger.Conditions>
<Setter Property="Background" Value="SlateGray" />
</MultiDataTrigger>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=(ListViewItem.IsSelected)}"
Value="False" />
<Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=(Panel.IsMouseOver)}"
Value="False" />
<Condition Binding="{Binding Locked}"
Value="True" />
</MultiDataTrigger.Conditions>
<MultiDataTrigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<ColorAnimation
Storyboard.TargetProperty="(Control.Background).(SolidColorBrush.Color)"
From="Red" To="White" Duration="0:0:0.2"
AutoReverse="True" RepeatBehavior="Forever" />
</Storyboard>
</BeginStoryboard>
</MultiDataTrigger.EnterActions>
</MultiDataTrigger>
</Style.Triggers>
</Style>