Elements and Attributes in XAML - Document Elements
(Page 2 of 4 )
Document elements handle document presentation. Documents are categorized as either flow or fixed. The FixedDocument element is designed to be What You See Is What You Get (WYSIWYG) and is intended to appear in all formats (print, browser, application) with exactly the same layout.
A FlowDocument element provides more flexibility in appearance to enhance readability. Flow documents dynamically reformat content based on a variety of factors, including screen and page size, font size, and optional user preferences. Flow documents are comprised of one or more elements derived from Block or Inline . Block elements such as Block , Figure , Floater , List , ListItem , Paragraph , Section , Table , and TableCell are used to organize and format blocks of text. Inline elements are used to format text within a block. Inline elements are Bold , AccessKey , LineBreak , Hyperlink , Italic , Subscript , Superscript , and Underline .
Some of these elements might look familiar, such as Paragraph , Table , and Italic . Similar formatting elements exist in other user-interface markup languages, such as <p> , <table> , and <i> , respectively, in HTML. These elements are virtually identical in execution but have structural differences as well as an abundance of attributes in XAML that do not exist in their HTML counterparts.
While the core syntax of XAML is very similar to markup languages such as HTML, XAML user-interface elements are not restricted to containing traditional content. For example, a Button is not required, nor restricted, to present text-based content as a prompt. The flexibility of XAML and its object-oriented nature offer unlimited possibilities. You can just as easily decorate the face of a Button with any UIElement -derived element. Example 3-6 declares three circles—defined by an Ellipse element with equivalent x- and y-axis radii—as the content element of a Button . While content control-derived classes may only have one child element, that child element may contain additional elements, such as the DockPanel or StackPanel .
Example 3-6. Using alternate elements as the content of a Button
<StackPanel xmlns=http://schemas.microsoft.com/winfx/ avalon/2005
HorizontalAlignment="Center"
Margin="10">
<Button
Width="50 "
Height="100">
<DockPanel>
<Ellipse Margin="5"
DockPanel.Dock="Top"
Stroke="Black"
RadiusX="10"
RadiusY="10"
Fill="Red" />
<Ellipse Margin="5"
DockPanel.Dock="Top"
Stroke="Black"
RadiusX="10"
RadiusY="10"
Fill="Yellow" />
<Ellipse Margin="5"
DockPanel.Dock="Top"
Stroke="Black"
RadiusX="10"
RadiusY="10"
Fill="Green" />
</DockPanel>
</Button>
</StackPanel>
The result of evaluating Example 3-6 is shown in Figure 3-2.

Figure 3-2. Defining a content control with multiple child elements
Next: Attributes >>
More XML Articles
More By O'Reilly Media
|
This article is excerpted from chapter 3 of The Basics of XAML, written by Lori A. MacVittie (O'Reilly, 2006; ISBN: 0596526733). Check it out today at your favorite bookstore. Buy this book now.
|
|