DoubleAnimation/Storyboard不停
DoubleAnimation/Storyboard doesn't stop
全局变量:
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);
所以我的问题是为什么停止功能不起作用?
我想我误解了一些关于动画 class 或故事板的东西,但我现在无法理解。
请帮忙,谢谢。
只需要在启动时指定动画可控:
CursorAnimation.Begin(timeCurLine, true);
全局变量:
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);
所以我的问题是为什么停止功能不起作用?
我想我误解了一些关于动画 class 或故事板的东西,但我现在无法理解。
请帮忙,谢谢。
只需要在启动时指定动画可控:
CursorAnimation.Begin(timeCurLine, true);