Gus*_*nti 7 c# wpf animation synchronous
我有这样的东西:
scaleTransform.BeginAnimation(ScaleTransform.ScaleXProperty, shrinkAnimation);
scaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, shrinkAnimation);
MyDialog.Show();
Run Code Online (Sandbox Code Playgroud)
动画并行正确运行(x和y缩小在一起),但由于BeginAnimation是异步调用,因此Show()在动画仍在运行时执行该方法(假设shrinkAnimation运行1秒).
在打电话之前,我该如何等待动画完成Show()?
谢谢!
您可以使用具有Storyboard已完成事件的 来代替该BeginAnimation方法。这是一个设置不透明度的示例,但它是相同的概念:
DoubleAnimation animation = new DoubleAnimation(0.0, new Duration(TimeSpan.FromSeconds(1.0)));
Storyboard board = new Storyboard();
board.Children.Add(animation);
Storyboard.SetTarget(animation, MyButton);
Storyboard.SetTargetProperty(animation, new PropertyPath("(Opacity)"));
board.Completed += delegate
{
MessageBox.Show("DONE!");
};
board.Begin();
Run Code Online (Sandbox Code Playgroud)