WPF - synchronous animation

I have something like this:

scaleTransform.BeginAnimation(ScaleTransform.ScaleXProperty, shrinkAnimation); scaleTransform.BeginAnimation(ScaleTransform.ScaleYProperty, shrinkAnimation); MyDialog.Show(); 

The animation runs correctly in parallel (x and y are compressed together), but since BeginAnimation is an asynchronous call, the Show() method runs while the animation is still running (suppose shrinkAnimation works for 1 second).

How to wait for the animation to complete before calling Show() ?

Thanks!

+7
c # animation wpf synchronous
source share
1 answer

You can use a Storyboard that has a completed event, and not the BeginAnimation method. Here is an example that sets 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(); 
+4
source share

All Articles