2011-09-07 14 views
6

i scrivere il codice seguente:Come chiamare un metodo dopo aver completato uno storyboard?

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

ma non wwork corretta. L'animazione funziona bene, ma la rimozione è sbagliata. Come posso combinare uno Storyboard-End con la chiamata a un metodo?

Thnaks molto.

risposta

12

Come l'esecuzione dello storyboard è asincrona è necessario aggiungere un "Storyboard Completato" gestore di eventi:

story.Completed += new EventHandler(Story_Completed); 

quindi inserire il codice Rimuovere in quanto:

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

questo otterrà eseguito quando lo storyboard è completo.

Problemi correlati