WPF - ColorAnimation 完成事件

发布于 2024-08-06 14:32:07 字数 1091 浏览 1 评论 0原文

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

“无法在样式中的目标标记上指定事件‘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>

I want to be notified when the animation is completed.
However, when I apply the following code, I get the following error

"The event 'Completed' cannot be specified on a Target tag in a Style. Use an EventSetter instead."

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

酒儿 2024-08-13 14:32:07

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

编辑:你可以在退出操作中做任何你需要做的事情吗???

I think the issue is that WPF cannot 'smartly' hook up your OnColorAnimationCompleted event on your ListViewItem because it has no way of knowing what your ListViewItem's type is, and thus it cannot subscribe OnColorAnimationCompleted to the Completed event.

Edit: Can you do whatever you need to do in the exit actions???

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文