You ve now mastered the basics. You can write XAML and can compile, deploy, and run the resulting application. Unfortunately, the applications you ve learned to write so far are pretty boring. Chapter 3 dives into XAML in depth and shows you how to use a wide variety of UI objects provided by the Longhorn platform. Later chapters show you a number of the other new technologies that you can also use in your applications.
As you ve seen in Chapter 2, Longhorn platform applications typically consist of an
object and a set of
The Application object is a singleton and persists throughout the lifetime of the application. It allows your application logic to handle top-level events and share code and state among pages. The Application object also determines whether the application is a single window application or a navigation application.
You typically write each user interface page using a
You can also consider a XAML page to be a description of an object model. When the runtime creates the page, it instantiates each of the elements and nodes described in the XAML document and creates an equivalent object model in memory. You can manipulate this object model programmatically ” for example, you can add and remove elements and nodes to cause the page to render and behave differently.
Fundamentally, a XAML page describes the classes that the runtime should create, the property values and event handlers for the instances of the classes, and an object model hierarchy ”that is, which instance is the parent of another instance.
All XAML documents are well-formed XML documents that use a defined set of element names. Therefore, all rules regarding the formation of well-
Each XAML page contains one or more
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
Each element name corresponds to the
<Cell><TextBox Height="50">Nissan 350Z</TextBox></Cell>
<Cell><TextBox Height="50">Porsche Boxster</TextBox></Cell>
This XAML document creates an object hierarchy as shown in Figure 3-1 and the display shown in Figure 3-2.
Figure 3-1: An example XAML page object model
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
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.