I have something this:
scaleTransform.BeginAnimation(ScaleTransform.ScaleXProperty, shrinkAnimation);
scaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, shrinkAnimation);
MyDialog.Show();
The animations run correctly in parallel (x and y shrink together), but because BeginAnimation
is an asynchronous call, the Show()
method gets executed while the animation is still running (suppose shrinkAnimation
runs for 1 second).
How can I wait for animations to complete before calling Show()
?
Thanks!
You can use a Storyboard
, which has a completed event, instead of that BeginAnimation
method. Here's an example, setting opacity, but it's the same concept:
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With