Ugrás a tartalomhoz

.NET Programming Technologies

Gergely Kovásznai, Csaba Biró

Eszterházy Károly College

11. fejezet - Animations (written by Biró Csaba)

11. fejezet - Animations (written by Biró Csaba)

The animation is actually rapid projected succession of images. We need to revise our knowledge about dependency properties, managed events, and triggers. WPF provides 42 animation classes located in the System.Windows.Media.Animation namespace.

These classes can be classified into the following three groups:

  1. Linear animations:

Animations in this group can be used most commonly because of their simplicity.

Actually, the value of a dependency property changes gradually from a starting and the final point. The linear animation format <Type>Animation, where <Type> is the name of the animation type, for example Color, Double, etc.

  1. Key frame-based animations:

An important feature of these animations that the beginning and the final value is not fixed (they are different from the previous one), so the value of the dependency property is changed arbitraryly at any given moment. The key frame-based animation format: <Type> AnimationUsingKeyFrames, where <Type> is the name of the animation type, for example: String, Double, etc.

  1. Path-based animations:

Path-based animations we can reach the movement of the object with tracking the specified path. The path-based animation format: <Type>AnimationUsingPath, where <Type> is the name of the animation type, for example: Point, Double, Matrix

Animations core classes

Familiarise two important classes before the widely investigation. The first is the Timeline as a centre element of every animations and the „father” of all the animation- types (e.g DoubleAnimation, MatrixAnimationUsingPath). The timeline is actually nothing more than a stretch of time, which has a starting point and a period of time can be assigned to it.

Its role is to oversee the set time frame, determines the length of time, the repetition, etc. Another important class is Storyboard actually perceived as a special timeline will be used for animation creation. This class will be responsible for controlling the animation of the child class (defines which object and property has to be targetted by animations).

<Storyboard>

                <DoubleAnimation Duration="0:0:10" From "1" To="200" />

</Storyboard>

The Duration attribute can specify the animation duration (in hours, minutes, second format). From signs the initial value of the related property, while To indicates the target one. You can use the By property aswell which is the difference between the initial and the final value. If To and By properties are given, the compiler ignores the value of the By property.

The linked property (TargetProperty) and the related object name (TargetName) can be indicated in two ways (Example XI.1, Example XI.2)

Example XI.1

<Storyboard TargetName="rect" TargetProperty="Height">

            <DoubleAnimation Duration="0:0:10" From "1" To="200" />

</Storyboard>

Example XI.2

<Storyboard>

        <DoubleAnimation Duration="0:0:10" From "1" To="200"

                        Storyboard.TargetName="rect"

                        Storyboard TargetProperty="Height">/>

</Storyboard>