0

谁能告诉我为什么在下面的代码中没有从集合中删除该项目?它穿过它而不扔,但 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
        }
    }
4

0 回答 0