2016-10-18 51 views
0

我有一個WPF應用程序,當數據源中的值已更新並且工作正常時,它會執行單元格閃爍。如何正確停止以編程方式聲明的故事板

我注意到,當我執行更新的應用程序分析真的很快,內存越來越大。由於我以這種方式啓動故事板

private static DoubleAnimation blink = 
     new DoubleAnimation() 
     { 
      From = 0, 
      To = 1, 
      Duration = TimeSpan.FromSeconds(0.2), 
      FillBehavior = FillBehavior.Stop 
     }; 
private void Items_ItemChanged(object sender, ItemChangedEventArgs<ExpandoObject> e) 
    { 
     var club = e.Item; 
     var row = grid.ItemContainerGenerator.ContainerFromItem(club) as Telerik.Windows.Controls.GridView.GridViewRow; 
     if (row != null) 
     { 
      var column = grid.Columns[e.PropertyName]; 
      var cell = row.Cells.FirstOrDefault(c => c.Column == column); 
      if (cell != null) //In case of virtualization I won't have all the columns 
      { 
       Storyboard.SetTarget(blink, cell.Content as TextBlock); 
       Storyboard.SetTargetProperty(blink, new PropertyPath(Button.OpacityProperty)); 
       var sb = new Storyboard(); 
       sb.Children.Add(blink); 
       sb.Begin(); 
      } 
     } 
    } 

我懷疑我必須停止動畫,但我不知道我該怎麼做呢?

感謝

回答

1

Items_ItemChanged取出Storyboard

Storyboard sb = new Storyboard(); 
    private void Items_ItemChanged(object sender, ItemChangedEventArgs<ExpandoObject> e) 
    { 
     sb.Stop(); 
     sb.Children.Clear(); 

     sb.Children.Add(blink); 

     var club = e.Item; 
     var row = grid.ItemContainerGenerator.ContainerFromItem(club) as Telerik.Windows.Controls.GridView.GridViewRow; 
     if (row != null) 
     { 
      var column = grid.Columns[e.PropertyName]; 
      var cell = row.Cells.FirstOrDefault(c => c.Column == column); 
      if (cell != null) //In case of virtualization I won't have all the columns 
      { 
       Storyboard.SetTarget(blink, cell.Content as TextBlock); 
       Storyboard.SetTargetProperty(blink, new PropertyPath(Button.OpacityProperty)); 

       sb.Begin(); 
      } 
     } 
    } 
+0

謝謝,這種方式我可以阻止它,或者它很好嗎? – advapi

+0

@advapi檢查並告訴 – AnjumSKhan

+0

你很棒,沒有更多的記憶成長! – advapi

0

的問題是,你每次都創建一個新的故事板,而不是項目變化重新使用現有的一個:

var sb = new Storyboard(); 

如果你真的必須這樣做,那麼你需要處理的情節提要完成事件並將其從小區中移除。

相關問題