The preceding example used a DoubleAnimation to animate a property. In addition to the DoubleAnimation type, Silverlight provides several more animation objects. Because animations generate property values, different animation types exist for different property types. To animate a property that takes a Double value, such as the Width property of an element, use an animation that produces Double values, such as the DoubleAnimation. To animate a property that takes a Point value, use an animation that produces Point values, such as the PointAnimation, and so on.
Silverlight provides two categories of animation types: From/To/By animations and key-frame animations. The following table describes the animation categories and their naming conventions.
Category | Description | Naming convention |
|---|
From/To/By animation | Animates between a starting and ending value: To specify a starting value, set the From property of the animation. To specify an ending value, set the To property of the animation. To specify an ending value relative to the starting value, set the By property of the animation (instead of the To property).
The examples in this overview use these animations, because they are the simplest to implement. | typeAnimation |
Key-frame animation | Animates between a series of values specified using key-frame objects. Key-frame animations are more powerful than From/To/By animations because you can specify any number of target values and even control their interpolation method. Key-frame animations are described in detail in Key-Frame Animations. | typeAnimationUsingKeyFrames |
The following table shows several common animation types and some properties that they are used with.
Animations Are Timelines
All animations inherit from the Timeline object; therefore, all animations are specialized types of timelines. A Timeline defines a segment of time. You can specify the timing behaviors of a timeline: its Duration, how many times it is repeated, and even how fast it progresses.
Because an animation is a Timeline, it also represents a segment of time. An animation calculates output values as it progresses though its specified segment of time (or Duration). As the animation progresses, or "plays," it updates the property that it is associated with.
Three frequently used timing properties are Duration, AutoReverse, and RepeatBehavior.
Duration Property
A timeline (and therefore, an animation) represents a segment of time. The length of that segment is determined by the Duration property of the timeline, which is usually specified by using a TimeSpan value. When a timeline reaches the end of its duration, it has completed an iteration.
An animation uses its Duration property to determine its current value. If you do not specify a Duration value for an animation, it uses the default value of one second.
The following syntax shows a simplified version of the XAML attribute syntax for the Duration property.
hours : minutes : seconds |
The following table shows several Duration settings and their resulting values.
Setting | Resulting value |
|---|
0:0:5.5 | 5.5 seconds. |
0:30:5.5 | 30 minutes and 5.5 seconds. |
1:30:5.5 | 1 hour, 30 minutes, and 5.5 seconds. |
For more information about Duration values and the XAML syntax, see the Duration property reference page.
AutoReverse Property
The AutoReverse property specifies whether a timeline plays backward after it reaches the end of its Duration. If you set this animation property to true, an animation reverses after it reaches the end of its Duration, playing from its ending value back to its starting value. By default, this property is false.
RepeatBehavior Property
The RepeatBehavior property specifies how many times a timeline plays. By default, a timeline has an iteration count of 1.0, which means it plays one time and does not repeat.