WPF-彩色动画完成事件

WPF-彩色动画完成事件,wpf,animation,coloranimation,Wpf,Animation,Coloranimation,我希望在动画完成时收到通知。 然而,当我应用下面的代码时,我得到了下面的错误 “无法在样式中的目标标记上指定事件‘已完成’。请改用EventSetter。” 我认为问题在于WPF无法在ListViewItem上“智能”连接OnColorAnimationCompleted事件,因为它无法知道ListViewItem的类型,因此无法将OnColorAnimationCompleted订阅到已完成事件 编辑:您可以在退出操作中执行任何需要执行的操作吗?谢谢!我遇到的真正问题是,一旦动画完成,我想强制

我希望在动画完成时收到通知。 然而,当我应用下面的代码时,我得到了下面的错误

“无法在样式中的目标标记上指定事件‘已完成’。请改用EventSetter。”


我认为问题在于WPF无法在ListViewItem上“智能”连接OnColorAnimationCompleted事件,因为它无法知道ListViewItem的类型,因此无法将OnColorAnimationCompleted订阅到已完成事件


编辑:您可以在退出操作中执行任何需要执行的操作吗?

谢谢!我遇到的真正问题是,一旦动画完成,我想强制控件的颜色为原始颜色。原因是,如果动画在短时间内多次启动,则颜色不会设置回其原始颜色。我的问题的解决办法是停止这种行为。“通过将FillBehavior设置为Stop,可以告诉动画在其活动期结束后停止影响其目标属性。”感谢您的回答,这有助于我进一步了解WPF。干杯
<Style x:Key="CredentialEntryListViewItemStyle" TargetType="{x:Type ListViewItem}" BasedOn="{StaticResource alternatingListViewItem}">
  <Setter Property="HorizontalContentAlignment" Value="Stretch" />
  <Setter Property="VerticalContentAlignment" Value="Stretch" />
  <Style.Triggers>
    <DataTrigger Binding="{Binding IsDuplicated}" Value="True">
      <DataTrigger.EnterActions>
        <BeginStoryboard>
          <Storyboard>
            <ColorAnimation AutoReverse="True" 
                            RepeatBehavior="2x"
                            Completed="OnColorAnimationCompleted"
                            Storyboard.TargetProperty="Foreground.(SolidColorBrush.Color)" 
                            To="Orange" Duration="0:0:0.3"/>
          </Storyboard>
        </BeginStoryboard>
      </DataTrigger.EnterActions>
    </DataTrigger>
  </Style.Triggers>
</Style>