Animations are simply the visual result of changing property values on objects over a period of time. To move something on the screen you
might change the Left
and Top
properties, to make something fade in or out you change the object's Opacity
, and so on.
While it's possible to create animations manually in code, it is usually better to utilize the optimized animation capabilities of Silverlight.
Here are the main classes you will come across when working with animations.
BeginStoryboard
- An action that starts the contained Storyboard.Storyboard
- Contains one or more animations that are applied to objects.DatatypeAnimation
- Changes the desired property values.You must use the correct type of animation depending on the data type of the property you are animating.
If the property data type is...
Double
, use DoubleAnimation
.Color
, use ColorAnimation
.Point
, use PointAnimation
.
For key-frame animations you'll use the UsingKeyFrames variant, such as DoubleAnimationUsingKeyFrames
with
a collection of key-frames that use the desired interpolation method.
Animations can be started automatically based on Triggers. The following
shows starting an animation using the Canvas.Loaded
event and the <BeginStoryboard>
action.
Silverlight 1.0 only supports starting an animation on the Loaded
event for an object.
Animations can also be controlled interactively from code using the Begin()
, Pause()
, Resume()
, Stop()
and Seek()
methods. In XAML, use the x:Name
attribute to specify
an ID for the storyboard you wish to control.
In Silverlight 1.0 you could use the following mouse event handler to start the animation.
Related information on the web is listed below.