tags:

views:

168

answers:

1

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!

+1  A: 

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();
Mike Pateras