如何等待动画完成? [英] How to wait untill a animation is finished?
问题描述
嗨
我有一个名为fadeTo()
的函数,该函数可更改动画的不透明度.我想知道如何等待fadeTo
中的情节提要和动画完成,然后继续执行我的程序的其余部分.
例如,如果我按下按钮,我希望image1淡出然后制作新图像.但是发生的事情是它只是在淡入时间之前制作了一个新图像,所以不会有任何效果:
Hi
i have a function called fadeTo()
which changes an opacity with an animation. i want to know how can i wait until the storyboard and animation in fadeTo
are finished then continue the rest of my program.
for example if i hit on button i want image1 to fade out and then make a new image. but what happens is it just makes a new image before the fade time so there will be no effect:
private void button_Click(object sender, RoutedEventArgs e)
{
//fadeTo(Control, OpacityToFade, Duration);
fadeTo(image1, 0.0, 500);
//I want the program to wait here till the fade finishes but i dont know how to?
image1 = new Image();
.
.
.
}
我该怎么办?
感谢
How can i do it?
thanks
推荐答案
对于动画完成后的执行任务,可以使用如果您没有动画类,但是具有动画的持续时间(例如您的情况),则可以使用
If you don''t have the animation class but you have the duration of the animation (like in your case), you can use a Timer with that duration.
我不建议在这里使用
Thread.Sleep
方法,因为我们不想阻止UI ...I don''t suggest to use the
Thread.Sleep
method here, because we don''t want to block the UI...
除了我的第一个解决方案外,我还记得两个月前我已经发布了解决此问题的技巧(我怎么会忘记它呢……:)).
In addition to my first solution, I just remembered that I''ve already posted a tip for solving this issue, two months ago (How could I forget it... :) ).
您可以尝试使用我的 SuspendedButton .在
BeforeClick
事件处理程序中,启动动画,然后在Click
事件处理程序中,执行动画完成后必须完成的任务.You can try to use my SuspendedButton. In the
BeforeClick
event-handler, start the animation and, in theClick
event-handler, perform the task that has to be done after the animation is finished.
这篇关于如何等待动画完成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!