2011-09-07 9 views
6

i escriba el siguiente código:¿Cómo llamar a un método después de que se terminó un Guión gráfico?

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

pero no wwork correcta. La animación funciona bien, pero la eliminación es incorrecta. ¿Cómo puedo combinar un Storyboard-End con la llamada a un método?

Thnaks mucho.

Respuesta

12

A medida que la ejecución del guión gráfico es asíncrono es necesario agregar un "Storyboard Completado" controlador de eventos:

story.Completed += new EventHandler(Story_Completed); 

a continuación, poner el código Quitar hecho de que:

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

Esto se ejecutan cuando el Storyboard finaliza.

Cuestiones relacionadas