我已经用一种方法启动了动画,后来如果它还没有完成,我将不得不停止它并立即完成它。
Vector diff = ...
DoubleAnimation aniX = new DoubleAnimation(diff.X, TimeSpan.FromSeconds(0.4));
DoubleAnimation aniY = new DoubleAnimation(diff.Y, TimeSpan.FromSeconds(0.4));
aniX
而aniY
被停止,如果他们没有完成。
我认为您应该使用XAML
附加了某些代码的代码Trigger
来阻止它。以编程方式停止动画。您可以尝试使用Begin
来开始Storyboard
和Stop
停止它(不要使用BeginAnimation
):
Storyboard st = new Storyboard();
Storyboard.SetTarget(aniX, yourObject);
Storyboard.SetTargetProperty(aniX, yourPropertyPath);
st.Children.Add(aniX);
Storyboard.SetTarget(aniY, yourObject);
Storyboard.SetTargetProperty(aniY, yourPropertyPath);
st.Children.Add(aniY);
//begin
st.Begin();
//stop
st.Stop();
注意:上面的代码假定您在过程代码(不是XAML代码)中声明所有DoubleAnimations
和Storyboard
。我认为您应该在XAML
代码中声明它们以使其更加简洁,其中许多类和内容WPF
已针对进行了优化XAML
,因此有时您会觉得在过程代码中看起来有些奇怪。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句