Animating both values at the same time

Is it possible to implement resize window of two values “height, “width” in one moment? Without waiting for the action of one and after the other? :PaimonNomming:

        private void ResizeWindow(double width, double height)
        {
            Duration duration = TimeSpan.FromSeconds(2);

            DoubleAnimation widthAnimation = new DoubleAnimation();
            widthAnimation.To = width;
            widthAnimation.Duration = duration;

            DoubleAnimation heightAnimation = new DoubleAnimation();
            heightAnimation.To = height;
            heightAnimation.Duration = duration;

            Storyboard storyboard = new Storyboard();
            storyboard.Children.Add(widthAnimation);
            storyboard.Children.Add(heightAnimation);
            Storyboard.SetTarget(widthAnimation, this);
            Storyboard.SetTarget(heightAnimation, this);
            Storyboard.SetTargetProperty(widthAnimation, new PropertyPath(Window.WidthProperty));
            Storyboard.SetTargetProperty(heightAnimation, new PropertyPath(Window.HeightProperty));

            storyboard.Begin();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            ResizeWindow(640, 360);
        }
Was this page helpful?