XAML Elements


Each XAML page contains one or more elements that control the layout and behavior of the page. You arrange these elements hierarchically in a tree. Every element has only one parent. Elements can generally have any number of child elements. However, some element types ”for example, Scrollbar ” have no children; and other element types ”for example, Border ” can have a single child element.

Each element name corresponds to the name of a managed class. Adding an element to a XAML document causes the runtime to create an instance of the corresponding class. For example, the following markup represents a root DockPanel element that has a single child Table element. The Table element contains three child Row elements. Each Row element contains three children, and a few of them have child text nodes.

 <Border xmlns="http://schemas.microsoft.com/2003/xaml" 
Background="BlanchedAlmond">
<DockPanel>
<Table>
<Body>
<Row>
<Cell><Button/></Cell>
<Cell><Text>Item</Text></Cell>
<Cell><Text>Price</Text></Cell>
</Row>
<Row>
<Cell><CheckBox Checked="true"/></Cell>
<Cell><TextBox Height="50">Nissan 350Z</TextBox></Cell>
<Cell><TextBox Height="50">29.95</TextBox></Cell>
</Row>
<Row>
<Cell><CheckBox/></Cell>
<Cell><TextBox Height="50">Porsche Boxster</TextBox></Cell>
<Cell><TextBox Height="50">9.95</TextBox></Cell>
</Row>
</Body>
</Table>
</DockPanel>
</Border>

This XAML document creates an object hierarchy as shown in Figure 3-1 and the display shown in Figure 3-2.

click to expand
Figure 3-1: An example XAML page object model
click to expand
Figure 3-2: The display from the previous XAML

You can access much of the functionality of such objects using only markup. Using only markup, you can do any of the following:

  • Describe a hierarchical set of objects that the runtime will instantiate

  • Set object properties to values known statically

  • Set object properties to values retrieved from a data source

  • Cause changed property values to be stored back into the data source

  • Repeatedly change a property s value over time

  • Bind an event handler to an object s event

However, although you can create some amazing user interfaces using only markup, you can also access an element s functionality programmatically using the XAML object model. The object model allows you to manipulate every aspect of the elements on a page. It actually provides additional capabilities that are not accessible through XAML.

Every XAML element derives from System.Windows.UIElement or System.Windows.ContentElement , and therefore all elements possess a number of common features. Elements can be grouped in the following four basic categories:

  • Controls derive from System.Windows.Control and handle user interaction.

  • Panels are specialized controls that derive from System.Windows.Panel and handle page layout and act as containers for elements.

  • Text formatting elements derive from System.Windows.TextElement and handle text formatting and document structure.

  • Shapes handle vector graphic shapes.




Introducing Microsoft WinFX
Introducing WinFX(TM) The Application Programming Interface for the Next Generation of Microsoft Windows Code Name Longhorn (Pro Developer)
ISBN: 0735620857
EAN: 2147483647
Year: 2004
Pages: 83
Authors: Brent Rector

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net