gpt4 book ai didi

c# - 将项目添加到 ListView 时,MultiDataTrigger 的 EnterActions 中的 ColorAnimation 不触发

转载 作者:可可西里 更新时间:2023-11-01 12:05:28 25 4
gpt4 key购买 nike

我有一个 ListView,AlternationCount 设置为 2。我有一个 ListViewItem 样式,当前将 ListViewItem 的背景颜色设置为交替颜色,我想添加第三个触发器,它触发 ColorAnimation 来为红色之间的颜色设置动画当绑定(bind)的 ViewModel 的属性为真时为 White(在本例中为名为“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>

最佳答案

我没有适合您示例的特定语法,但您可以尝试将触发器直接放在 ListView 上(而不是资源中)并使用 ListView.ItemContainerStyle 而不是 Syle。我无法使下面的简单代码在 Resouces 中工作,但是当我将它直接移动到 ListView 时它起作用了。我可能在资源中遇到语法错误,例如

    <ListView AlternationCount="2"
ItemsSource="{Binding Path=...}">
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Style.Triggers>
<!-- setting up triggers for alternate background colors -->
<Trigger Property="ItemsControl.AlternationIndex" Value="1">
<Setter Property="Background" Value="Gainsboro"></Setter>
</Trigger>
<Trigger Property="ItemsControl.AlternationIndex" Value="2">
<Setter Property="Background" Value="White"></Setter>
</Trigger>
</Style.Triggers>
</Style>
</ListView.ItemContainerStyle>
<ListView.View>

关于c# - 将项目添加到 ListView 时,MultiDataTrigger 的 EnterActions 中的 ColorAnimation 不触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5173645/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com