Chapter 5. Introducing XAML

XAML is an XML dialect, so you’ll see a lot of angle brackets here and throughout this book. In this chapter, we will have a look at the most important XAML elements used in a Silverlight application. It is virtually impossible to cover them all in a book of this size, but we will present as many as possible to let you dive into XAML with maximum speed and get a sense of the power of Silverlight markup.

If you have already worked with XAML for WPF applications, you already know most of what is covered in this chapter (and most of Chapter 7 as well). However, there are some subtle differences: Silverlight does not support the full XAML format that WPF does, but only a (quite decent) subset. Future releases of Silverlight will increase the percentage of supported WPF elements and attributes, but some things just will not work in a web browser as they do in a desktop application.

In Silverlight 1.0, the root element of every XAML file is <Canvas>, which defines the area that holds the Silverlight content (Positioning Elements later will show other uses for the <Canvas> element). This has changed with Silverlight 2, providing you with more flexibility. However, when you are using the Silverlight Script web site template, you indeed have <Canvas> as your root element, in the following fashion:

<Canvas xmlns="http://schemas.microsoft.com/client/2007" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  ...
</Canvas>  

If you are using the Silverlight Project ...

Get Essential Silverlight 2 Up-to-Date now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.