WPF - 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>
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为问题是 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???