// Animate the scale of a Rectangle from 1 to 2 over 2 seconds var myRectangle = new Rectangle(); var myAnimation = new DoubleAnimation(1, 2, TimeSpan.FromSeconds(2)); myRectangle.BeginAnimation(Rectangle.ScaleTransformProperty, myAnimation);
// Animate the opacity of a TextBlock from 0 to 1 over 1 second var myTextBlock = new TextBlock() { Text = "Hello, World!" }; var myAnimation = new DoubleAnimation(0, 1, TimeSpan.FromSeconds(1)); myTextBlock.BeginAnimation(TextBlock.OpacityProperty, myAnimation);In this example, we create a TextBlock and a DoubleAnimation that animates its Opacity property from 0 to 1 over 1 second. We then call BeginAnimation() on the TextBlock and provide the property to animate and the animation object. Package library for this code example: PresentationFramework