410Microsoft Visual Studio 2010: A Beginner’s Guide

XML Application Markup Language (XAML), pronounced “Zamel,” is an XML- based language for building user interfaces. You’ll find XAML being used in both

Windows Presentation Foundation (WPF) and Silverlight applications. WPF is for desktop application development, and Silverlight is for Web-based development. Both WPF and Silverlight have much in common through programming with XAML. Therefore, this Appendix provides an introduction to XAML and shows you how to perform layouts, which are common to both WPF and Silverlight. This Appendix can be useful before reading the WPF and Silverlight chapters so that you can get the most out of what is specific to each technology. For simplicity, I’ll demonstrate concepts by using a WPF application, but what you learn will be applicable to both WPF and Silverlight. Before reading this Appendix, you might want to read or review Appendix A for an introduction to XML, which will provide you with familiarity of basic XML syntax.

Starting a WPF Project

As you are reading a book about VS, it’s only natural that you would want to experience XAML from within the VS IDE. As stated earlier, we’ll use a WPF Application project for describing XAML because it has fewer files and is simpler than a Silverlight application. To create the WPF Application project, select File New Project and select WPF Application in the New Project window. Name the application anything you like and click OK. What you’ll see is a new project that has Window1.xaml file open in VS with contents similar to Listing B-1.

Listing B-1 A new XAML file

<Window x:Class="WpfApplication1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525">

<Grid>

</Grid>

</Window>

In VS, the default layout for Window1.xaml is to have a visual designer on the top half of the work window and XAML in the lower half. You can view the full XAML document by grabbing the top edge of the XAML half and dragging it to the top of the screen so that you are only looking at the XAML editor. The first thing you should notice about Listing B-1

Page 433
Image 433
Microsoft 9GD00001 manual Starting a WPF Project, Listing B-1 a new Xaml file