C# DoubleAnimation已完成事件未触发

C# DoubleAnimation已完成事件未触发,c#,wpf,C#,Wpf,好的,我正在做一个项目,我们有各种各样的动画,其中的一些让我头疼。特别是从网格中删除UIElement的。动画确实会出现,但元素不会被物理删除。以下是我们用于删除的代码: public static void RemoveChildAnimate(UIElement child, Grid grid) { DoubleAnimation an = new DoubleAnimation(1.0, 0, TimeSpan.FromMilliseconds(100))

好的,我正在做一个项目,我们有各种各样的动画,其中的一些让我头疼。特别是从网格中删除UIElement的。动画确实会出现,但元素不会被物理删除。以下是我们用于删除的代码:

    public static void RemoveChildAnimate(UIElement child, Grid grid)
    {
        DoubleAnimation an = new DoubleAnimation(1.0, 0, TimeSpan.FromMilliseconds(100));
        child.BeginAnimation(btnDugmeTemp.OpacityProperty, an);

        DoubleAnimation da = new DoubleAnimation(1.0, 0, TimeSpan.FromMilliseconds(100));
        da.Completed += (object sender, EventArgs e) => { grid.Children.Remove(child); };

        ScaleTransform rt = new ScaleTransform();
        child.RenderTransformOrigin = new Point(0.5, 0.5);
        child.RenderTransform = rt;
        rt.BeginAnimation(ScaleTransform.ScaleXProperty, da);
        rt.BeginAnimation(ScaleTransform.ScaleYProperty, da);
    }
btnDugmeTemp代码:

public partial class btnDugmeTemp : UserControl
{
    public event EventHandler click;

    public btnDugmeTemp()
    {
        InitializeComponent();

        this.gdMain.MouseDown += gdMain_MouseDown;
    }

    void gdMain_MouseDown(object sender, MouseButtonEventArgs e)
    {
        if (click != null)
        {
            DoubleAnimation da = new DoubleAnimation(1.0, 0.95, TimeSpan.FromMilliseconds(50));
            da.AutoReverse = true;
            ScaleTransform rt = new ScaleTransform();
            this.RenderTransformOrigin = new Point(0.5, 0.5);
            this.RenderTransform = rt;
            rt.BeginAnimation(ScaleTransform.ScaleXProperty, da);
            rt.BeginAnimation(ScaleTransform.ScaleYProperty, da);
            click(this, null);
        }
    }

    public static readonly DependencyProperty ImageProperty =
        DependencyProperty.Register("btnImage", typeof(ImageSource), typeof(btnDugmeTemp));

    public static readonly DependencyProperty textProperty =
        DependencyProperty.Register("btnText", typeof(string), typeof(btnDugmeTemp));


    public ImageSource btnImage 
    {
        get { return this.Image.Source; }
        set { this.Image.Source = value; }
    }

    public string btnText 
    {
        get { return this.Text.Content.ToString(); }
        set { this.Text.Content = value; }
    }

    public Brush btnBackColor
    {
        get { return this.gdMain.Background; }
        set { this.gdMain.Background = value; }
    }

}

什么是btnDugmeTemp?这是一个用户控件,我将添加代码。