DoubleAnimation完成事件未触发

时间:2014-01-29 10:21:43

标签: c# wpf

好的,所以我正在开展一个项目,我们有各种各样的动画,而这些让我头疼。特别是从网格中删除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; }
    }

}

0 个答案:

没有答案