Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any event that fires when WPF animation ends?

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);
}
like image 943
Terminador Avatar asked Feb 08 '12 13:02

Terminador


1 Answers

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);
}
like image 147
Lyndon White Avatar answered Oct 22 '22 06:10

Lyndon White