With all the necessary tools installed, you can now create your first Silverlight application. Launch Visual Studio 2008 and create a new project. In the Project types, select Silverlight and then select the Silverlight Project template (see Figure 1
). Name the project OurFirstSilverlightProject
Figure 1. First Step: Creating a new Silverlight project.
Figure 2. The Foundation: All the basic files contained within the Silverlight project.
In the Solution Explorer, click the Show All Files button to reveal all the files that Visual Studio has added for the project. Figure 2 shows the files contained within it.
The following sections explain the basic files contained within a Silverlight project.
HTML pages that host Silverlight controls can also contain other normal HTML elements that make up a web page. When you double-click on the TestPage.html file in Solution Explorer, Visual Studio 2008 will display the page in Split view, a new feature available in Visual Studio 2008. Using the Split view, you can view the HTML code and at the same time preview how it looks in a browser (see Figure 3).
|Figure 3. Test Case: Displaying an HTML page in Split view.|
This file contains the UI for your Silverlight application. Listing 3 shows the default content created by Visual Studio 2008.
Take note here of the x:Class attribute. In Listing 3, it specifies that the code-behind Class name is OurFirstSilverlightProject.Page (OurFirstSilverlightProject is the default root namespace of our project while Page is the class name), and its corresponding assembly is located in ClientBin/OurFirstSilverlightProject.dll.
Visual Studio 2008 provides IntelliSense support for XAML content, which is quite a handy feature if you're considering writing XAML manually.
This file contains the managed source code of our Silverlight application. The default class name used by Visual Studio 2008 is Page (Listing 4).
The Page.xaml.vb file is where you write your managed code. When a Silverlight application is ready for deployment, only the compiled assembly needs to be deployed. There is no need to deploy the source code.
This is the file provided by Microsoft that creates all the necessary plumbing needed to ensure that the target Web browser is able to run your Silverlight applications. By including this file in your application, the target Web browser will be asked to download the necessary runtime if the Silverlight runtime is not installed (every Silverlight application must include this file). Under the License Agreement, you are not allowed to modify this file. For Web servers that serve multiple Silverlight applications, you can simply put a single copy of this file in one location and set all the pages containing Silverlight content to point to this page.