How to call a method after a storyboard?

i write the following code:

public void name(object sender, RoutedEventArgs e) { DoubleAnimation myDoubleAnimation = new DoubleAnimation(); myDoubleAnimation.From = 1.0; myDoubleAnimation.To = 0.0; myDoubleAnimation.Duration = new Duration(TimeSpan.FromSeconds(0.2)); sb1 = new Storyboard(); sb1.Children.Add(myDoubleAnimation); Storyboard.SetTargetName(myDoubleAnimation, one.Name); Storyboard.SetTargetProperty(myDoubleAnimation, new PropertyPath(Grid.OpacityProperty)); sb1.Begin(this); if (one.Opacity == 0) { Container_one.Children.Remove(one); } } 

but it does not work correctly. The animation works fine, but Remove is wrong. How can I combine a Storyboard-End with a method call?

Thnaks a lot.

+6
source share
1 answer

Since the storyboard is asynchronous, you need to add the "Storyboard Completed" event handler:

 story.Completed += new EventHandler(Story_Completed); 

then put the Remove code in this:

 private void Story_Completed(object sender, EventArgs e) { if (one.Opacity == 0) { Container_one.Children.Remove(one); } } 

This will be done after the storyboard is completed.

+12
source

Source: https://habr.com/ru/post/896782/


All Articles