2012-02-08 11 views
8

C'è qualche evento che si attiva quando termina l'Animazione WPF?C'è qualche evento che si attiva quando termina l'animazione WPF?

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); 
} 

risposta

16

Sì, c'è.

the Completed Event (MSDN)


Così il codice diventa:

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); 

} 
Problemi correlati