Graphics Reference
In-Depth Information
The RepeatBehavior="Forever" setting ensures that the clock hand will con-
tinue moving as long as the application is running; as soon as the value reaches
the “To” destination, it “wraps around” to the “From” value and continues the
animation. 7
You may well wonder about the accuracy of the actual animation, considering
how precise the specifications are. Will the animation operate if the CPU is
under heavy load or is insufficiently powered?
Although the smoothness of the animation may suffer (become “jumpy”) when
the CPU is stressed, the image will keep up with where it needs to be at any
given time. The animation engine works in an absolute way—newly calculat-
ing where the property values should be at the present time—instead of in a
relative way based on accumulating deltas. Thus, even if the application has
been denied adequate CPU time for a long period, the image will jump to
the correct state when the application next receives sufficient CPU cycles for
image refreshing.
The final step is to install the animation in the XAML code. We want the
animation to start as soon as the clock face is made visible. Thus, we create an
EventTrigger and use it to set the Triggers property of the canvas. A trigger
must specify what type of event launches it (in this case, as soon as the canvas's
content has been fully loaded) and what action it performs (in this case, a set
of three simultaneous animation elements, encapsulated into what WPF calls a
Storyboard ):
<Canvas ... >
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
The specification of the clock scene should be located here.
<Canvas.Triggers>
<EventTrigger RoutedEvent="FrameworkElement.Loaded">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="ActualTimeHour"
Storyboard.TargetProperty= "Angle"
From= "0.0" To= "360.0"
Duration= "01:00:00.00" RepeatBehavior= "Forever" />
Two more DoubleAnimation elements should be located
here to animate the other clock hands.
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Canvas.Triggers>
</Canvas>
7. Other available behavior types include reverse motion (i.e., “bouncing back”) and sim-
ply stopping (for “one-shot” motions).
 
Search WWH ::




Custom Search