2011-09-07 43 views
6

i viết Bộ luật sau:Làm thế nào để gọi một phương thức sau khi Bảng phân cảnh kết thúc?

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

nhưng nó không wwork đúng. Hoạt ảnh hoạt động tốt, nhưng Xóa là sai. Làm thế nào tôi có thể kết hợp một Storyboard-End với các cuộc gọi đến một methode?

Thnaks rất nhiều.

Trả lời

12

Khi thực hiện các Storyboard là không đồng bộ bạn cần phải thêm một sự kiện handler "Storyboard Completed":

story.Completed += new EventHandler(Story_Completed); 

sau đó đặt mã Remove của bạn ở chỗ:

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

này sẽ được thực hiện khi Bảng phân cảnh hoàn thành.

Các vấn đề liên quan