DoubleAnimation animation = new DoubleAnimation(); animation.From = 0; animation.To = 300; animation.Duration = TimeSpan.FromSeconds(2); Rectangle rect = new Rectangle(); rect.Width = 0; rect.BeginAnimation(Rectangle.WidthProperty, animation);
DoubleAnimation animation = new DoubleAnimation(); animation.From = 0; animation.To = 1; animation.Duration = TimeSpan.FromSeconds(2); animation.AutoReverse = true; animation.RepeatBehavior = new RepeatBehavior(2); TextBlock textBlock = new TextBlock(); textBlock.Opacity = 0; textBlock.BeginAnimation(TextBlock.OpacityProperty, animation);In both examples, the DoubleAnimation class is used to define the start and end values of the animation as well as the duration of the animation. The animation is then applied to the specified property by calling the BeginAnimation method. The WPF library includes the System.Windows.Media.Animation namespace which provides classes for animating properties of UI elements.