Silverlight Templates

.Silverlight Templates
.Silverlight Templates

When you create a Silverlight project you have templates available as a starting point. Each template is designed to represent a certain type of application. The available templates depend upon your edition of Visual Studio. Below are the three Silverlight templates available in Visual Studio 2010 Professional. The available Silverlight templates depend upon the edition of Visual Studio. Examples of other Silverlight templates which are not covered in this article include: Silverlight Unit Test Application, Silverlight Business Application, WCF RIA Services Class Library.

Silverlight Application Template

.Silverlight Application Template

The "Silverlight Application Template" builds an runnable program. The first decision is if you wish to "Create a directory for the solution". Frequently a Silverlight project will also need a Web project, but it is not always necessary. If you do not need a web project, you can remove the check from the checkbox from "Create a directory for the solution", however a popup will still ask you if you wish to "Host the Silverlight application in a new Web site". You can remove the check from the checkbox from "Host the Silverlight application in a new Web site" and Visual Studio will not create a hosting web site. This option creates just one project (Web Site project is not created) and provides fewer files in the Solution Explorer. You can always associate the Silverlight project with a web project later. Even thought you selected NOT to have Visual Studio create a web site for your Silverlight application, you still get a web page when you run the application in Visual Studio. VS creates an HTML page in the build directory to host your Silverlight application and uses this when you run the application.

It you do create the select to "Host the Silverlight application in a new Web site" then a Silverlight and a Webpage project are created. You can view the properties on the Website project to see what applications are associated with the project. A ClientBin directory is created to hold the .zap file. An .aspx page is also created in case you want to add dynamic content, you can remove the .aspx file if you are not going to use it. The Silverlight.js file is used to detect if the Silverlight plugin is available if you wish to provide more graceful degradation than just prompting the user to install the Silverlight plugin. You can delete the Silverlight.js from the project if you are not going to use it.

Silverlight Navigation Application Template

.Silverlight Navigation Application Template

The "Silverlight Navigation Application template" includes additional code for providing web-like navigation amoung pages to the Silverlight Application template. These types of projects almost always have an associated web project. The default files include a Styles.xaml file and three pages (in .xaml). Navigation amont the pages is performed with the browser buttons. Silverlight plays some tricks with the browsers Forward and Back buttons to make sure the web page does not unload when using these buttons inside the Silverlight application.

Silverlight Class Library

.Silverlight Class Library

The "Silverlight Application Template" builds a library designed to be incorporated into other applications. Class libraries are used when you have code you wish to resuse in multiple applications. Also a class library is used when you have controls you wish to sell for other people to use in their applications.