XAML in a Nutshell - Elements
(Page 3 of 4 )
All XAML elements are an XML representation of CLR classes, but not all CLR classes are represented in XAML. Most of those represented are user-interface elements and are ultimately derived from System.Windows.UIElement, which provides basic visual user-interface properties that are shared by most XAML elements. A System.Windows.UIElement can render itself, receive input via the keyboard and mouse, visually size and position its child elements, and raise events.
Not all XAML elements are derived from System.Windows.UIElement . Some, such as LineBreak , TableColumn , and Document , are derived from System.Windows.FrameworkContentElement . System.Windows.FrameworkContentElement elements cannot render themselves but are instead rendered by another class, usually the container in which they have been placed.
Most XAML elements can be organized into five basic categories:
- Root elements
- Control elements
- Panel elements
- Shape and geometric elements
- Document elements
Root Elements Root elements function as the page’s base container for all user-interface elements. A page is required to have one root element. The most commonly used root elements are the panel elements—StackPanel, DockPanel , Canvas , and Grid —and Page , a root element that allows you to declaratively control a number of the properties of the window containing the XAML page. To be considered a root element, the element must be a container for at least one other element. (When displaying XAML output in XamlPad, you don’t have to include a root element because XamlPad provides it on your behalf.) You can create custom root elements by deriving new classes from Page or Window and exposing them as XAML elements.
The root element must contain a reference to the appropriate namespace (in most cases, the default Avalon namespace, http://schemas.microsoft.com/winfx/avalon/ 2005 ). As with all XML documents, unless otherwise specified, it is assumed that all elements in the page are associated with the default namespace declared on the root element. The declaration in XAML is the same as in any XML document.
<Page xmlns="http://schemas.microsoft.com/winfx/ avalon/2005" .../>
Next: Control Elements >>
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.
|
|