DoubleAnimation doubleAnimation = new DoubleAnimation(); doubleAnimation.From = 0; doubleAnimation.To = 100; doubleAnimation.Duration = TimeSpan.FromSeconds(2); Rectangle rect = new Rectangle(); rect.Width = 50; rect.Height = 50; rect.Fill = Brushes.Red; this.Content = rect; rect.BeginAnimation(Rectangle.WidthProperty, doubleAnimation);
Storyboard storyboard = new Storyboard(); DoubleAnimation doubleAnimation = new DoubleAnimation(); doubleAnimation.From = 0; doubleAnimation.To = 360; doubleAnimation.Duration = TimeSpan.FromSeconds(5); doubleAnimation.RepeatBehavior = RepeatBehavior.Forever; RotateTransform rotateTransform = new RotateTransform(); rect.RenderTransform = rotateTransform; storyboard.Children.Add(doubleAnimation); Storyboard.SetTarget(doubleAnimation, rotateTransform); Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath("Angle")); storyboard.Begin();In this example, we create a Storyboard object that contains a DoubleAnimation that animates a RotateTransform's Angle property from 0 to 360 degrees over a duration of 5 seconds. We then apply the animation to the RotateTransform using the ApplyAnimationClock method. Package library: WPF (Windows Presentation Foundation)