如何在C#/ WPF中停止动画?
时间:2020-03-05 18:41:36 来源:igfitidea点击:
我有这样的事情:
barProgress.BeginAnimation(RangeBase.ValueProperty, new DoubleAnimation( barProgress.Value, dNextProgressValue, new Duration(TimeSpan.FromSeconds(dDuration)));
现在,我们将如何停止该动画(" DoubleAnimation")?我之所以想这样做,是因为我想开始新的动画(这似乎奏效,但是很难说),并最终停止最后一个动画...
解决方案
回答
要停止它,请再次调用BeginAnimation,将第二个参数设置为null。
回答
将动画放置在StoryBoard中。在情节提要板上调用Begin()和Stop()以开始停止动画。
回答
使用情节提要板控制动画时,请确保将第二个参数设置为true,以便将动画设置为可控制的:
public void Begin( FrameworkContentElement containingObject, **bool isControllable** )
回答
If you want the base value to become the effective value again, you must stop the animation from influencing the property. There are three ways to do this with storyboard animations: Set the animation's FillBehavior property to Stop Remove the entire Storyboard Remove the animation from the individual property
从MSDN
如何:使用情节提要动画后设置属性
回答
在我的情况下,我必须使用两个命令,我的xaml有一个按钮,它会触发触发器,并且它的触发器会触发情节提要动画。
我放置了一个按钮来停止动画,并在其中添加以下代码:
MyBeginStoryboard.Storyboard.Begin(this, true); MyBeginStoryboard.Storyboard.Stop(this);
我不喜欢它,但是它确实在这里起作用。试试看!