即使在设置后,WPF 故事板动画也会永远循环 [英] WPF Storyboard Animation Loops Forever Even After Being Set

查看:87
本文介绍了即使在设置后,WPF 故事板动画也会永远循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义用户控件,可根据绑定到 DataTriggerDependencyProperty 设置动画.如果 DependencyProperty 等于 Failure,它应该为用户控件内的矩形(名为 buttonColor)的填充颜色设置动画.

I have a a custom user control to animate based on a DependencyProperty which is bound to a DataTrigger. If the DependencyProperty is equal to Failure, it should animate the fill color of a rectangle (named buttonColor) within the user control.

但出于某种原因,即使我将 RepeatBehavior 设置为包括 1 在内的任何值,它也会永远循环.

For some reason though, it always loops forever even if I set the RepeatBehavior to any value including 1.

如果我删除了 RepeatBehavior 属性,它只会播放一次动画(如预期).这是我遇到问题的代码:

If I remove the RepeatBehavior attribute, it only plays the animation once (as expected). Here is the code which I have the issue:

<DataTrigger Binding="{Binding Path=ButtonAction.Status}" Value="Failure">
    <DataTrigger.EnterActions>
        <StopStoryboard BeginStoryboardName="Pulse"/>

        <BeginStoryboard>
            <Storyboard RepeatBehavior="1">
                <ColorAnimation Storyboard.TargetName="buttonColor"
                                Storyboard.TargetProperty="Fill.Color" 
                                To="{StaticResource FailedColor}" 
                                AutoReverse="True" />
            </Storyboard>
        </BeginStoryboard>
    </DataTrigger.EnterActions>
</DataTrigger>

推荐答案

重复 N 次的正确语法是:

The correct syntax to repeat N times is:

<Storyboard RepeatBehavior="Nx">

例如:

<Storyboard RepeatBehavior="6x">

这篇关于即使在设置后,WPF 故事板动画也会永远循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆