我正在尝试为网格上的背景颜色设置动画以更改,一旦事件发生,但我无法让它工作,我可以让它立即改变颜色(通过数据触发器),但只要我尝试将动画引入其中,然后我无法使其正常工作(动画似乎没有生效)。
这是我正在使用的当前 XAML(尽管我尝试了各种变体并且无法让它动画化):
<DataTrigger Binding="{Binding ElementName=me, Path=Viewed}" Value="False">
<Setter Property="Background" Value="LightYellow" />
<DataTrigger.ExitActions>
<BeginStoryboard>
<Storyboard>
<ColorAnimation Duration="00:00:02" To="White" Storyboard.TargetProperty="(Grid.Background).(SolidColorBrush.Color)"/>
</Storyboard>
</BeginStoryboard>
</DataTrigger.ExitActions>
</DataTrigger>
<!--
<DataTrigger Binding="{Binding ElementName=me, Path=Viewed}" Value="True">
<Setter Property="Background" Value="White" />
</DataTrigger>
-->
其中 Viewed 是我的控件上的依赖属性 (bool)。任何正确方向的提示将不胜感激。我还尝试将其设置为在 bool 切换为 true 时发生的引发事件上的 EventTrigger。