首页 新闻 会员 周边

WPF 动画如何停止

0
悬赏园豆:20 [已解决问题] 解决于 2014-02-20 12:55

我的代码如下

private Storyboard pathAnimationStoryboard = new Storyboard();
private MatrixAnimationUsingPath matrixAnimation = new MatrixAnimationUsingPath();

private void Begin()

{

Img_dh.RenderTransformOrigin = new Point(0.1, 0.1);
Canvas.SetLeft(Img_dh, -Img_dh.ActualWidth * Img_dh.RenderTransformOrigin.X);
Canvas.SetTop(Img_dh, -Img_dh.ActualHeight * Img_dh.RenderTransformOrigin.Y);
MatrixTransform MatrixTransform_01 = new MatrixTransform();
this.RegisterName("MatrixTransform_01", MatrixTransform_01);
Img_dh.RenderTransform = MatrixTransform_01;
Point centerPt = new Point(75, 76);
ese1.Margin = new Thickness(centerPt.X, centerPt.Y, 0, 0); //指示中心点
Canvas.SetLeft(ese1, -ese1.ActualWidth / 2);
Canvas.SetTop(ese1, -ese1.ActualHeight / 2);

PathGeometry aniPath = new PathGeometry();
EllipseGeometry egStandard = new EllipseGeometry(centerPt, 50, 50);
aniPath.AddGeometry(egStandard);
matrixAnimation.PathGeometry = aniPath; //动画的路径
matrixAnimation.Duration = TimeSpan.FromSeconds(3);
matrixAnimation.RepeatBehavior = RepeatBehavior.Forever;
matrixAnimation.DoesRotateWithTangent = true;
Storyboard.SetTargetName(matrixAnimation, "MatrixTransform_01"); //动画的对象
Storyboard.SetTargetProperty(matrixAnimation, new PropertyPath(MatrixTransform.MatrixProperty));
pathAnimationStoryboard.Children.Add(matrixAnimation);
pathAnimationStoryboard.Begin(this);

}

请问如何停止这个动画呢?求大神解答

wpf
JesseWong的主页 JesseWong | 初学一级 | 园豆:5
提问于:2014-02-20 08:59
< >
分享
最佳答案
0

pathAnimationStoryboard.Remove(this);

收获园豆:20
cenlo | 小虾三级 |园豆:583 | 2014-02-20 10:32

这个也不行

JesseWong | 园豆:5 (初学一级) | 2014-02-20 10:56

@JesseWong: 你在启动的时候pathAnimationStoryboard.Remove(this,true);

cenlo | 园豆:583 (小虾三级) | 2014-02-20 11:01

@cenlo: 

JesseWong | 园豆:5 (初学一级) | 2014-02-20 11:05

@JesseWong: 呃。。错了。 应该是你在启动的时候pathAnimationStoryboard.Begin(this,true);复制下来忘改了

cenlo | 园豆:583 (小虾三级) | 2014-02-20 11:11

@cenlo: 依然还是不行啊

JesseWong | 园豆:5 (初学一级) | 2014-02-20 11:15

@cenlo: 我在上面设置了matrixAnimation.RepeatBehavior = RepeatBehavior.Forever;

是不是由于它的原因

JesseWong | 园豆:5 (初学一级) | 2014-02-20 11:15

@JesseWong: 那你可以把它取消试一下

cenlo | 园豆:583 (小虾三级) | 2014-02-20 11:23

@cenlo: 还是不行

JesseWong | 园豆:5 (初学一级) | 2014-02-20 11:25

@JesseWong: pathAnimationStoryboard.Begin(this);这里的this你改在动画运动的对像Img_dh,pathAnimationStoryboard.Begin(Img_dh,true);

pathAnimationStoryboard.Remove(Img_dh);

cenlo | 园豆:583 (小虾三级) | 2014-02-20 11:38

@cenlo: 还是不行

JesseWong | 园豆:5 (初学一级) | 2014-02-20 12:34

@JesseWong: 呃。。这个我已经试过了,是可以的呀

cenlo | 园豆:583 (小虾三级) | 2014-02-20 12:38

@cenlo: 好了,谢谢你

JesseWong | 园豆:5 (初学一级) | 2014-02-20 12:54

@cenlo: 可是图片不见了啊

JesseWong | 园豆:5 (初学一级) | 2014-02-20 13:16

@JesseWong: 呃。。。。这个你移出动画后重新设置图片呢

cenlo | 园豆:583 (小虾三级) | 2014-02-20 13:46

@cenlo: 如何获取动画停止后Img_dh的 Canvas.Left和Canvas.Top的值呢

JesseWong | 园豆:5 (初学一级) | 2014-02-20 14:58
其他回答(4)
0

z知道begin怎么就不知道stop呢?

hailants | 园豆:750 (小虾三级) | 2014-02-20 09:09

Stop不行啊

支持(0) 反对(0) JesseWong | 园豆:5 (初学一级) | 2014-02-20 09:21
0

播放完了就停止了。

Launcher | 园豆:45045 (高人七级) | 2014-02-20 09:17

matrixAnimation.RepeatBehavior = RepeatBehavior.Forever;这里设置的循环播放

支持(0) 反对(0) JesseWong | 园豆:5 (初学一级) | 2014-02-20 09:24
0

你设置的永久循环播放怎么停啊 matrixAnimation.RepeatBehavior = RepeatBehavior.Forever; 里面有一个是播放一次就停止的

c#牛刀小试 | 园豆:44 (初学一级) | 2014-08-18 11:18
0

还有个办法是用其他动画替代现有动画,设置一个0秒的现有新动画,用ApplyAnimationClock替换原有动画

zjjjjjj | 园豆:206 (菜鸟二级) | 2017-06-27 13:25
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册