WPF - 颜色动画完成事件

标签 wpf animation coloranimation

我想在动画完成时收到通知。
但是,当我应用以下代码时,出现以下错误

“无法在样式中的目标标签上指定事件 'Completed'。请改用 EventSetter。”

<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>

最佳答案

我认为问题在于 WPF 无法“巧妙地”将 OnColorAnimationCompleted 事件连接到 ListViewItem 上,因为它无法知道 ListViewItem 的类型是什么,因此它无法将 OnColorAnimationCompleted 订阅到 Completed 事件。

编辑:你能在退出 Action 中做任何你需要做的事情吗???

关于WPF - 颜色动画完成事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1506725/

相关文章:

c# - 背景在 Mouse_Leave 中发生变化,但在 Mouse_Enter 中没有变化

c# - 在 WPF 中限制 "Auto"和 "1*"上的行高

c# - 如何避免使用 System.Reflection 在 ComboBox 中显示枚举属性值

jQuery SlideIn 动画到 Angular 中的 CSS 动画

Window.Resources 内的 WPF ColorAnimation

c# - WPF 中的数独 - 我应该为表格使用什么基本元素?

c# - 如何在 XAML 和 C# 中为 WPF 按钮的旋转设置动画?

ios - 如何使用自定义动画将一个 UI 元素替换为另一个 UI 元素?

wpf - 使用 ColorAnimation 更改 StackPanel 背景颜色

c# - 无法为颜色属性设置动画,因为对象已密封或卡住