DoubleAnimation / Storyboard不会停止

时间:2018-07-17 01:42:35

标签: c# wpf animation storyboard controls

全局变量:

private DoubleAnimation AnimateCursor = new DoubleAnimation();
private Storyboard CursorAnimation = new Storyboard();

初始化部分:

AnimateCursor.From = 0;
AnimateCursor.To = 1150;
AnimateCursor.Duration = new Duration(TimeSpan.FromSeconds(30));
AnimateCursor.RepeatBehavior = RepeatBehavior.Forever;

Storyboard.SetTargetName(AnimateCursor, "timeCurLine");
Storyboard.SetTargetProperty(AnimateCursor, new PropertyPath(Canvas.LeftProperty));

CursorAnimation.Children.Add(AnimateCursor);

最后,我添加以下代码来控制动画的开始和停止:

public void StartNavCursor() => CursorAnimation.Begin(timeCurLine);
public void StopNavCursor() => CursorAnimation.Stop(timeCurLine);

所以我的问题是为什么停止功能不起作用?

我想我误解了有关动画课或情节提要的东西,但现在我还不明白。

请帮助,谢谢。

1 个答案:

答案 0 :(得分:0)

您只需要在启动动画时指定动画是可控的:

CursorAnimation.Begin(timeCurLine, true);