'How to start and stop animation in avalonia

In Avalonia, how to start and stop in keyframe animations

private Animation StartAnimation(Control control)
        {
            Animation animation = new Animation();
            animation.Duration = TimeSpan.FromMilliseconds(1000);
            animation.IterationCount = new IterationCount(2);

            KeyFrame key1 = new KeyFrame();
            key1.KeyTime = TimeSpan.FromMilliseconds(500);
            key1.Setters.Add(new Avalonia.Styling.Setter(WidthProperty, 50 + 10d));
            key1.Setters.Add(new Avalonia.Styling.Setter(HeightProperty, 50 + 10d));
            key1.Setters.Add(new Avalonia.Styling.Setter(OpacityProperty, 1));
            animation.Children.Add(key1);
            return animation;
        }


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source