© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
3 replies
Watashi o yūwaku suru

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);
        }
        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);
        }
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ How do I add priority when both threads are outputting at the same time?
C#CC# / help
8mo ago
✅ Winforms: open two forms at the same time
C#CC# / help
3y ago
❔ Iteration over multiple objects at the same time
C#CC# / help
3y ago