AnimationTimeline Class
Defines a segment of time over which output values are produced. These values are used to animate a target property.
Assembly: PresentationCore (in PresentationCore.dll)
An AnimationTimeline is a type of Timeline object that generates output values based on its timing progress. All animation types inherit from AnimationTimeline.
Freezable Features: Because it inherits from the Freezable class, the AnimationTimeline class provides several special features: AnimationTimeline objects can be declared as resources, shared among multiple objects, made read-only to improve performance, cloned, and made thread-safe. For more information about the different features provided by Freezable objects, see the Freezable Objects Overview.
Notes to Inheritors:To create a custom animation, override or implement the following members:
CreateInstanceCore – If your new class is concrete, you must override CreateInstanceCore to return a new instance of your class.
GetCurrentValue – Override this method to return the current value of your animation. It takes three parameters: a default origin value, a default destination value, and an AnimationClock. Use the AnimationClock to obtain the current time or progress for the animation. You can choose whether to use the default origin and destination values.
IsDestinationDefault – Override this property to indicate whether your animation uses the default destination value specified by the GetCurrentValue method.
TargetPropertyType – Override this property to indicate the Type of output your animation produces.
If the class does not use dependency properties to store its data or it requires extra initialization after creation, you might need to override additional methods; see the Freezable Objects Overview for more information.
For more information about creating custom animations, see the Custom Animations Overview.
This example shows one way to apply an animation to a property without using a Storyboard.
Note: |
|---|
This functionality is not available in Extensible Application Markup Language (XAML). For information about animating a property in XAML, see How to: Animate a Property by Using a Storyboard. |
To apply a local animation to a property, use the BeginAnimation method. This method takes two parameters: a DependencyProperty that specifies the property to animate, and the animation to apply to that property.
The following example shows how to animate the width and background color of a Button.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '''This sample demonstrates how to apply non-storyboard animations to a property. '''To animate in markup, you must use storyboards. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Imports System Imports System.Windows Imports System.Windows.Navigation Imports System.Windows.Media Imports System.Windows.Media.Animation Imports System.Windows.Shapes Imports System.Windows.Controls Namespace Microsoft.Samples.Animation.LocalAnimations ' Create the demonstration. Public Class LocalAnimationExample Inherits Page Public Sub New() WindowTitle = "Animate Property Example" Dim myStackPanel As New StackPanel() myStackPanel.Margin = New Thickness(20) ' Create and set the Button. Dim aButton As New Button() aButton.Content = "A Button" ' Animate the Button's Width. Dim myDoubleAnimation As New DoubleAnimation() myDoubleAnimation.From = 75 myDoubleAnimation.To = 300 myDoubleAnimation.Duration = New Duration(TimeSpan.FromSeconds(5)) myDoubleAnimation.AutoReverse = True myDoubleAnimation.RepeatBehavior = RepeatBehavior.Forever ' Apply the animation to the button's Width property. aButton.BeginAnimation(Button.WidthProperty, myDoubleAnimation) ' Create and animate a Brush to set the button's Background. Dim myBrush As New SolidColorBrush() myBrush.Color = Colors.Blue Dim myColorAnimation As New ColorAnimation() myColorAnimation.From = Colors.Blue myColorAnimation.To = Colors.Red myColorAnimation.Duration = New Duration(TimeSpan.FromMilliseconds(7000)) myColorAnimation.AutoReverse = True myColorAnimation.RepeatBehavior = RepeatBehavior.Forever ' Apply the animation to the brush's Color property. myBrush.BeginAnimation(SolidColorBrush.ColorProperty, myColorAnimation) aButton.Background = myBrush ' Add the Button to the panel. myStackPanel.Children.Add(aButton) Me.Content = myStackPanel End Sub End Class End Namespace
For the complete sample, see Local Animations Sample.
A variety of animation classes in the System.Windows.Media.Animation namespace exist for animating different types of properties. For more information about animating properties, see Animation Overview. For more information about dependency properties (the type of properties that are shown in these examples) and their features, see Dependency Properties Overview.
There are other ways to animate without using Storyboard objects; for more information, see Property Animation Techniques Overview.
More Code
| How to: Animate a Property by Using a Storyboard | This example shows how to use a Storyboard to animate properties. To animate a property by using a Storyboard, create an animation for each property that you want to animate and also create a Storyboard to contain the animations. |
System.Windows.Threading.DispatcherObject
System.Windows.DependencyObject
System.Windows.Freezable
System.Windows.Media.Animation.Animatable
System.Windows.Media.Animation.Timeline
System.Windows.Media.Animation.AnimationTimeline
System.Windows.Media.Animation.BooleanAnimationBase
System.Windows.Media.Animation.ByteAnimationBase
System.Windows.Media.Animation.CharAnimationBase
System.Windows.Media.Animation.ColorAnimationBase
System.Windows.Media.Animation.DecimalAnimationBase
System.Windows.Media.Animation.DoubleAnimationBase
System.Windows.Media.Animation.Int16AnimationBase
System.Windows.Media.Animation.Int32AnimationBase
System.Windows.Media.Animation.Int64AnimationBase
System.Windows.Media.Animation.MatrixAnimationBase
System.Windows.Media.Animation.ObjectAnimationBase
System.Windows.Media.Animation.Point3DAnimationBase
System.Windows.Media.Animation.PointAnimationBase
System.Windows.Media.Animation.QuaternionAnimationBase
System.Windows.Media.Animation.RectAnimationBase
System.Windows.Media.Animation.Rotation3DAnimationBase
System.Windows.Media.Animation.SingleAnimationBase
System.Windows.Media.Animation.SizeAnimationBase
System.Windows.Media.Animation.StringAnimationBase
System.Windows.Media.Animation.ThicknessAnimationBase
System.Windows.Media.Animation.Vector3DAnimationBase
System.Windows.Media.Animation.VectorAnimationBase
Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Note: