WPF 故事板动画即使在设置后也永远循环
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17032404/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
WPF Storyboard Animation Loops Forever Even After Being Set
提问by AXG1010
I have a a custom user control to animate based on a DependencyPropertywhich is bound to a DataTrigger. If the DependencyPropertyis equal to Failure, it should animate the fill color of a rectangle (named buttonColor) within the user control.
我有一个自定义用户控件可以根据DependencyProperty绑定到DataTrigger. 如果DependencyProperty等于Failure,它应该为用户控件内的矩形(名为 buttonColor)的填充颜色设置动画。
For some reason though, it always loops forever even if I set the RepeatBehaviorto any value including 1.
但出于某种原因,即使我将 设置为RepeatBehavior包括 1 在内的任何值,它也会永远循环。
If I remove the RepeatBehavior attribute, it only plays the animation once (as expected). Here is the code which I have the issue:
如果我删除 RepeatBehavior 属性,它只会播放一次动画(如预期)。这是我遇到问题的代码:
<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>
回答by Federico Berasategui
The correct syntax to repeat Ntimes is:
重复N时间的正确语法是:
<Storyboard RepeatBehavior="Nx">
for example:
例如:
<Storyboard RepeatBehavior="6x">
回答by jogi
Setting a duration value will also limit the repeat behavior as it takes precedence. So if you have repeat behavior set on the ColorAnimationUsingKeyFrames tag but on the storyboard you set a Duration="0:0:4" then the animation will only repeat for 4 seconds.
设置持续时间值也将限制重复行为,因为它优先。因此,如果您在 ColorAnimationUsingKeyFrames 标签上设置了重复行为,但在情节提要上设置了 Duration="0:0:4",那么动画只会重复 4 秒。

