Working with the Silverlight Project Templates

Once you have installed the Silverlight 5 Tools, you will find a number of project templates have been added to Visual Studio's New Project dialog under the Silverlight category (as shown in Figure 1-1).

images

Figure 1-1. The New Project window

Let's take a look at when and how you would use each of these project templates.

Silverlight Application

Silverlight Application is a basic project template for Silverlight projects; it simply includes a single blank view for the user interface. Back in Silverlight 2, this was the only project template available to create a Silverlight application, and it didn't provide much to get you started (it was just a blank slate). This project template might still be useful when creating widgets, games, banners, advertisements, and video players, for example—where an initial project infrastructure isn't particularly required. For business applications, on the other hand, you will find the Silverlight Navigation Application or Silverlight Business Application project templates that were introduced with Silverlight 3 a much better starting point.

Silverlight Navigation Application

Silverlight 3 introduced a navigation framework that essentially provides an application framework for Silverlight applications. This project template implements the navigation framework and provides a good starting point for building applications that contain multiple views. We'll take a look at the features of the navigation framework in Chapter 3.

Silverlight Business Application

The Silverlight Business Application template is similar to the Silverlight Navigation Application template, but with a number of additional features. It automatically assumes you want a web application project and links the Silverlight project and the web application project with WCF RIA Services. It includes login/registration screens and some built-in authentication functionality. In addition, all strings are stored in resource files so that the application can be easily localized and support different languages. This will be the template you will usually base your business applications on.

images Note If you don't see the Silverlight Business Application project template in the New Project dialog, ensure that you have selected version 4 of the .NET Framework in the framework selection drop-down.

Silverlight Class Library

A Silverlight Class Library project is essentially the same as a standard class library project but is marked for use in Silverlight projects (because Silverlight has its own version of the .NET Framework). You might use this project template if you were creating a custom control library, reusable code library, or business logic library, for example.

images Note Silverlight projects cannot reference assemblies targeting the full .NET Framework. However, projects targeting the full .NET Framework can reference Silverlight assemblies. Therefore, if you need to share a class library assembly between both types of projects, your best option is to create a Silverlight class library. Alternatively, you could create two projects (one for each project type) and link the files between them—a technique that may be useful if you have additional functionality not supported by Silverlight that you want to add to the class library targeting the full .NET Framework.

WCF RIA Services Class Library

The default scenario for WCF RIA Services assumes that you will create your business objects to be shared between the server and the client within your web project, and these will be replicated within your Silverlight project. However, this scenario doesn't create an ideal separate “middle tier” where your business objects are contained within a separate assembly that can then be reused between applications. This is where the WCF RIA Services Class Library project template comes in. When you use this template, it creates not one but two separate projects (one for the server and the other for the client) that are linked. Also, the automatic business object replication is done between these two projects rather than your Silverlight and web projects, providing much more flexibility and enabling a much better structure for your solution. This will be discussed further in Chapter 4.

images Note As with the Silverlight Business Application template, the WCF RIA Services Class Library template will not appear in your project templates if you do not have version 4 of the .NET Framework selected in the framework selection drop-down.

Silverlight Unit Test Application

The Silverlight Unit Test Application project template is installed with the Silverlight Toolkit. This creates a project that you can use to unit test your Silverlight application with the Silverlight Unit Test Framework.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset