Graphics Reference
In-Depth Information
Inline Exercise 2.7: The more complex a template is, the more value its
reusability provides. Add some additional visual elements to the clock-hand
template (e.g., a thin line bisecting it longitudinally), or give it a more com-
plex shape . . . and watch how its instances automatically adapt to show the
template's new definition.
Hint: The ControlTemplate will complain if you put more than one prim-
itive inside it, so you'll need to wrap its contents in a Canvas element. (Indeed,
Canvas is used for multiple purposes, including acting as a general-purpose
wrapper around multiple primitives.) Don't put any attributes in the Canvas
start tag for this usage.
Our use of this simple clock-hand template is a very basic, single-level
example of hierarchical modeling, which is a sophisticated technique for
constructing highly complex objects and scenes. See Chapter 6 for a proper
introduction to, and example of, this technique.
2.5 Dynamics in 2D Graphics Using WPF
A retained-mode architecture supports the implementation of simple dynamics;
the application focuses on maintaining the scene graph (including keeping it in
sync with the application model if one is present), and the platform carries the
burden of keeping the displayed image in sync with the scene graph. In this sec-
tion, we examine two types of dynamics available to WPF applications:
• Automated, noninteractive dynamics in which 2D shapes are manipulated
by animation objects specified in XAML
• And traditional user-interface dynamics, in which methods written in pro-
cedural code (callbacks) are activated by user manipulation of GUI con-
trols, such as buttons, list boxes, and text-entry areas
2.5.1 Dynamics via Declarative Animation
WPF provides the ability to specify simple animations without procedural code,
via XAML animation elements that can force object properties to change using
interpolation over time. The application creates an animation element, connects
it to the property to be manipulated, and specifies the animation's characteristics:
starting value, ending value, speed of interpolation, and desired behavior at ter-
mination (e.g., that the animation should be repeated when the ending value is
reached). Lastly, the application specifies what event should trigger the start of
the animation. Once set up, the animation element works automatically, without
the need for intervention by the application.
Virtually every XAML element property can be the target of an animation.
Examples include the following.
• The origin point of a shape (e.g., the upper-left corner of an ellipse) can be
manipulated by an animation element to make the shape appear to vibrate.
• The fill-color, edge-color, and edge-thickness properties of a shape prim-
itive can be manipulated by an animation element to perform feedback
animations, such as glowing or pulsing.
 
 
 
 
Search WWH ::




Custom Search