Graphics Reference
In-Depth Information
2.3.3.1 Lowest Layer: Object-Oriented API
The core layer is a set of classes providing all WPF functionality. Program-
mers can use any of the Microsoft .NET languages (e.g., C# or Visual Basic)
or Dynamic Language Runtime languages (such as IronRuby) to specify appli-
cation appearance and behavior at this level. A WPF application can be created
via this layer alone, but the other two layers provide improvements in developer
efficiency and convenience, and the ability to include designers and implementers
in less technical roles.
2.3.3.2 Middle Layer: XAML
The middle layer provides an alternative way to specify a large subset of the
functionality of the API, via the declarative language XAML, whose syntax is
readily understandable by anyone familiar with HTML or XML. Its declarative
nature facilitates support for rapid prototyping via interpreted execution, and it is
more conducive to use by nonprogrammers (in the same way that HTML is more
approachable than PostScript).
2.3.3.3 Highest Layer: Tools
As with any language, there is a learning curve associated with adopting XAML.
The highest layer of the WPF application/developer interface comprises the util-
ities that designers and engineers can use to generate XAML, including tools for
drawing graphics (e.g., Microsoft Expression Design or Adobe Illustrator), build-
ing 3D geometric models (e.g., ZAM 3D), and creating sophisticated user inter-
faces (e.g., Microsoft Expression Blend or ComponentArt Data Visualization).
2.4 Specifying a 2D Scene Using WPF
As explained earlier, WPF provides for both the construction of user-interface
regions and the specification of what we call “2D scenes.” The former is beyond
the scope of this textbook, so our focus here is on the specification of 2D scenes.
2.4.1 The Structure of an XAML Application
Throughout Section 2.4, we'll be building a simple XAML application that dis-
plays the analog clock shown in Figure 2.6.
If you are familiar with HTML syntax, XAML should be instantly accessi-
ble. An HTML file specifies a multimedia web page by creating a hierarchy of
elements —with the root being <HTML> , its children being <HEAD> and <BODY> ,all
the way down to paragraph and “text-span” elements for formatting, such as <B>
for boldface and <I> for italics. Other elements provide support for media presen-
tation and script execution.
An XAML program similarly specifies a hierarchy of elements. However, the
set of element types is distinct to XAML, and includes layout panels (e.g., a Stack-
Panel for arranging tightly packed controls/menus, and a Grid for creating spread-
sheetlike layouts), user-interface controls (e.g., buttons and text-entry boxes), and
a rectangular “blank slate” scene-drawing area called the Canvas .
In a fully formed application, like the one shown in Figure 2.1, the applica-
tion's appearance is specified via a hierarchy of layout panels, UI controls, and
a Canvas element acting as the viewport displaying the application's scene; how-
ever, for our first simple XAML example, let's just create a standalone Canvas :
Figure
2.6:
WPF-based
clock
application.
 
 
 
 
Search WWH ::




Custom Search