Window freeze after animation with TranslateTransform.YProperty & TranslateTransform.XProperty

Feb 5 at 7:50 AM
Hello
I am using the WPF.MDI for baseof mdi project in wpf.
I am trying to do animation that the window grows and moves at the same time. the this goes well but after the animation finishes , the window disappears on minimize or hangs on maximize.

Orig Code:

private void AddAnimationToMdiChild(UIElement target, Point from, Point to, Point height, Point width, TimeSpan speed, Action completed = null)
    {
        try
        {
            TransformGroup grp = new TransformGroup();

            //var rotate = new RotateTransform(16);
            //grp.Children.Add(rotate);


            var trans = new TranslateTransform();
            grp.Children.Add(trans);

            target.RenderTransform = grp;

            DoubleAnimation aniY = new DoubleAnimation(from.Y, to.Y, speed);
            DoubleAnimation aniX = new DoubleAnimation(from.X, to.X, speed);

            DoubleAnimation aniWidth = new DoubleAnimation()
            {
                From = width.X,
                To = width.Y,
                Duration = speed
            };

            DoubleAnimation aniHeight = new DoubleAnimation()
            {
                From = height.X,
                To = height.Y,
                Duration = speed
            };

            Storyboard.SetTarget(aniWidth, target);
            Storyboard.SetTarget(aniHeight, target);

            Storyboard.SetTargetProperty(aniWidth, new PropertyPath(Window.HeightProperty));
            Storyboard.SetTargetProperty(aniHeight, new PropertyPath(Window.WidthProperty));

            Storyboard sb = new Storyboard();
            sb.Children.Add(aniHeight);
            sb.Children.Add(aniWidth);

            aniX.Completed += (o, e) =>
            {
                trans.BeginAnimation(TranslateTransform.XProperty, null);
                sb.FillBehavior = FillBehavior.Stop;
                aniX.FillBehavior = FillBehavior.Stop;
                //TransformGroup tg = target.RenderTransform as TransformGroup;
                //TranslateTransform t = new TranslateTransform(); // Use new TranslateTransform here

                //t.X = (tg.Children[0] as TranslateTransform).X == 0.0 ? to.X + 1 : (tg.Children[0] as TranslateTransform).X + 1;
                //t.Y = (tg.Children[0] as TranslateTransform).Y == 0.0 ? to.Y + 1 : (tg.Children[0] as TranslateTransform).Y + 1;
                //tg.Children[0] = t;
            };

            aniY.Completed += (o, e) =>
            {
                trans.BeginAnimation(TranslateTransform.YProperty, null);
                sb.FillBehavior = FillBehavior.Stop;
                aniY.FillBehavior = FillBehavior.Stop;
                //TransformGroup tg = target.RenderTransform as TransformGroup;
                //TranslateTransform t = new TranslateTransform(); // Use new TranslateTransform here
                //t.X = (tg.Children[0] as TranslateTransform).X == 0.0 ? to.X + 1 : (tg.Children[0] as TranslateTransform).X + 1;
                //t.Y = (tg.Children[0] as TranslateTransform).Y == 0.0 ? to.Y + 1 : (tg.Children[0] as TranslateTransform).Y + 1;
                //tg.Children[0] = t;
            };

            aniWidth.Completed += (o, e) =>
            {
                sb.BeginAnimation(FrameworkElement.WidthProperty, null);
                sb.FillBehavior = FillBehavior.Stop;
                aniWidth.FillBehavior = FillBehavior.Stop;
                //((MdiChild)target).Width = width.Y;
            };

            aniHeight.Completed += (o, e) =>
            {
                sb.BeginAnimation(FrameworkElement.HeightProperty, null);
                sb.FillBehavior = FillBehavior.Stop;
                aniHeight.FillBehavior = FillBehavior.Stop;
                //((MdiChild)target).Height = height.Y;
            };

            trans.BeginAnimation(TranslateTransform.XProperty, aniX);
            trans.BeginAnimation(TranslateTransform.YProperty, aniY);
            sb.Begin();
        }
        catch (Exception ex)
        {

        }
    }
Please help
S. Akons
Feb 5 at 7:15 PM
Issue fixed
Apperently before using animation on mdi window , one need to set initial values for the window height,width x locatin and y location.
s.Akons