如何为DoubleAnimation的结束添加事件处理程序?

3

我正在使用DoubleAnimation而不是使用StoryBoard,并且我正在尝试将事件处理程序应用于完成时(否则,在动画结束之前,我要做的代码就会发生)。

我已经使用了:

da = new DoubleAnimation(40,20,  new Duration(TimeSpan.FromSeconds(2)));

((PerspectiveCamera)_Main3D.Camera).
    BeginAnimation(PerspectiveCamera.FieldOfViewProperty, da);

da.Completed += new EventHandler(Story_Completed);

然而,这种情况从未发生。

1个回答

5

您是在启动动画之后再附加事件处理程序。如果动画很短,则可能会在分配Completed处理程序之前完成动画。另外,当运行动画时,动画对象可能不会响应处理程序的分配。

请尝试以下方法:

da = new DoubleAnimation(40,20,  new Duration(TimeSpan.FromSeconds(2)));

da.Completed += new EventHandler(Story_Completed);

((PerspectiveCamera)_Main3D.Camera).
    BeginAnimation(PerspectiveCamera.FieldOfViewProperty, da);

在开始动画之前,请添加“完成”处理程序...

谢谢,那就是问题所在,现在它可以工作了。长命百岁,繁荣昌盛! - eric.itzhak

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接