任何人都可以告诉我为什么在以下代码中没有从集合中删除该项目?它在没有抛出的情况下贯穿它,但sv.Count始终保持不变,并且项目永远不会被删除。
public static void FadeOutAndRemove(ScatterView sv, ScatterViewItem svi)
{
try
{
svi.Opacity = 1.0;
var a = new DoubleAnimation
{
From = 1.0,
To = 0.0,
FillBehavior = FillBehavior.Stop,
BeginTime = TimeSpan.FromSeconds(0),
Duration = new Duration(TimeSpan.FromSeconds(0.5))
};
var storyboard = new Storyboard();
storyboard.Children.Add(a);
Storyboard.SetTarget(a, svi);
Storyboard.SetTargetProperty(a, new PropertyPath(UIElement.OpacityProperty));
storyboard.Completed += delegate {
svi.Visibility = Visibility.Hidden;
sv.Items.Remove(svi);
svi.Content = null;
svi = null;
};
storyboard.Begin();
}
catch (Exception ex)
{
//Handle error
}
}