13

Is there any event that fires when WPF Animation ends?

void HideDefaultScreenImageTimer_Tick(object sender, EventArgs e)
{
    HideDefaultScreenImageTimer.Stop();

    var doubleAnimation = new DoubleAnimation(1, 0, new Duration(TimeSpan.FromSeconds(0.45)));
    DefaultScreenImage.BeginAnimation(UIElement.OpacityProperty, doubleAnimation);
    // I need some event when an animation ENDS and within that event I want to remove 
    // Image (DefaultScreenImage) from Canvas.
    MainCanvas.Children.Remove(DefaultScreenImage);
}
Pang
  • 9,564
  • 146
  • 81
  • 122
Terminador
  • 1,328
  • 4
  • 14
  • 23

1 Answers1

24

Yes there is.

The Completed Event (MSDN).


So your code becomes:

void HideDefaultScreenImageTimer_Tick(object sender, EventArgs e)
{
    HideDefaultScreenImageTimer.Stop();

    var doubleAnimation = new DoubleAnimation(1, 0, new Duration(TimeSpan.FromSeconds(0.45)));
    doubleAnimation.Completed += (sender, eArgs) => MainCanvas.Children.Remove(DefaultScreenImage);

    DefaultScreenImage.BeginAnimation(UIElement.OpacityProperty, doubleAnimation);
}
Pang
  • 9,564
  • 146
  • 81
  • 122
Frames Catherine White
  • 27,368
  • 21
  • 87
  • 137