How to create a new Silverlight Project

Source: Internet
Author: User
Tags mscorlib visual studio 2010
How to create a new Silverlight Project Silverlight

The Silverlight project file is a text file that you can create and edit using different tools. For example, you can use Visual Studio 2010 and expression blend to create a Silverlight project or modify an existing project. For more information, see the expression blend document.

This topic describes how to use Visual Studio 2010 to create and generate a Silverlight application project or a Silverlight class library project, and how to add a Silverlight library assembly to a project. You need the following components to perform these steps:

  • Silverlight version 4.

  • Used for Silverlight 4 tools in Visual Studio 2010.

  • Visual Studio 2010.

This topic contains the following sections:

  • Silverlight Application Project

  • Silverlight Class Library Project

  • Add a Silverlight Library

{
Ca_click ('7096a579-400c-48ca-9c3f-0589eeffda0e ', 'expand', 'folder ')
} "Href =" javascript: void (0) "> Silverlight Application Project

Use"Silverlight application"Project template to create a Silverlight application project. Follow these steps to create a new Silverlight application project.

Create a new Silverlight Application Project
  1. Start Visual Studio 2010.

  2. In"File"Click"New"And then click"Project".

    Will display"New Project"Dialog box.

  3. In"Installed template"In the pane, expand"Visual C #"Or"Visual Basic"Node, and then select"Silverlight".

  4. In the template list, select"Silverlight application". Shows an example of a Silverlight Project template.

  5. Specify the name and location of the application, and then click"OK".

    Will display"Create a Silverlight application"Dialog box, as shown in.

  6. Select the method to host the Silverlight application.

    1. If you do not want to use a website to host the Silverlight application, deselect"Host the Silverlight application on the new website"Check box. Then, an HTML test page is generated to host the application.

    2. If you want to add a separate ASP. NET Website or ASP. NET web application project in the solution to host the Silverlight application, select"Host the Silverlight application on the new website"Check box. If you select this option, you must also specify"New web project name"And"New web project type".

  7. Slave"Silverlight version"Select the required Silverlight version from the drop-down list.

  8. Click"OK"Button.

  9. To generate a Silverlight application project, go"Generate"Click"Generate a solution".

  10. To debug a Silverlight application project, go"Debugging"Click"Start debugging".

  11. To run the Silverlight application project, go"Debugging"Click"Start execution (not debugging )".

Silverlight application project file

The Silverlight application project contains the following configuration, Assembly reference, and code files:

  • Appmanifest. xml

    This is the Application List file required to generate the application package. Do not edit this file.

  • Assemblyinfo. CS or assemblyinfo. VB

    This file contains the name and version metadata embedded into the generated assembly.

  • . Xap File

    This is the Silverlight application package. This file is generated when a Silverlight application project is generated. An application package is a compressed zip file with the. xap file extension and contains all the files required to start your application. For more information about the Silverlight application package, see application structure.

  • The Silverlight application project contains references to the following Assembly:

    • Mscorlib. dll

    • System. dll

    • System. Core. dll

    • System. net. dll

    • System. Windows. dll

    • System. Windows. browser. dll

    • System. xml. dll

  • Mainpage File

    You can use the mainpage class to create a user interface for the Silverlight application. The mainpage class is derived from usercontrol. You can implement the mainpage class by using mainpage. XAML (for the XAML tag) and mainpage. XAML. CS or mainpage. XAML. VB (for the code to hide.

  • APP files

    The Silverlight application needs to use the app class to display the application user interface. You can use app. XAML, app. XAML. CS, or app. XAML. VB to implement app classes. After creating an application package (. xap file), The Silverlight plug-in will instantiate the app class.

  • Test page

    If you"Create a Silverlight application"Not selected in the dialog box"Host the Silverlight application on the new website"To generate an HTML page (testpage.html) to host your application.

Silverlight application project website file

If"Create a Silverlight application"Select"Host the Silverlight application on the new website"Check box to create an ASP. NET Website and add it to the Silverlight solution. The website contains the following files:

  • Silverlight. js

    A JavaScript helper file that contains functions used to initialize the Silverlight plug-in instance and functions used to determine the installed plug-in version on the client.

  • HTML file

    The HTML file used to configure and instantiate the Silverlight plug-in. The plug-in downloads and runs the Silverlight application. The file name is connected by the Silverlight application project name and the text "testpage.html.

  • . Aspx File

    The. aspx file that starts the web page by default. The file name is connected by the Silverlight application project name and the text "testpage. aspx.

  • Web. config

    The website configuration file.

For more information about integrating Silverlight into your project, see integrate Silverlight with Web pages.

{
Ca_click ('4ca4ddea-a331-4b7f-ad9d-f6cc991096b6 ', 'expand', 'folder ')
} "Href =" javascript: void (0) "> Silverlight Class Library Project

Use"Silverlight class library"Project template to create a Silverlight class library project. Follow these steps to create a new Silverlight class library project.

Create a new Silverlight Class Library Project
  1. Start Visual Studio 2010.

  2. In"File"Click"New"And then click"Project".

    Will display"New Project"Dialog box.

  3. In"Installed template"In the pane, expand"Visual C #"Or"Visual Basic"Node, and then select"Silverlight".

  4. In the template list, select"Silverlight class library".

  5. Specify the name and location for the class library, and then click"OK".

    "Add Silverlight class library"The dialog box appears.

  6. Slave"Silverlight version"Select the required Silverlight version from the drop-down list, and then click"OK".

Silverlight class library project file

The Silverlight class library project contains the following configuration, Assembly reference, and code files:

  • Assemblyinfo. CS or assemblyinfo. VB

    This file contains the name and version metadata embedded into the generated assembly.

  • The Silverlight class library project contains references to the following Assembly:

    • Mscorlib. dll

    • System. dll

    • System. Core. dll

    • System. net. dll

    • System. Windows. dll

    • System. Windows. browser. dll

    • System. xml. dll

  • Class1. CS orClass1. VB

    Code file of a class named class1.

{
Ca_click ('7e356727-b02b-40e4-8f72-2821059e9b2e ', 'expand', 'folder ')
} "Href =" javascript: void (0) "> Add a Silverlight Library

When you install Silverlight 4 tools for Visual Studio 2010, the Silverlight core runtime assembly and the Silverlight SDK are installed. The Silverlight SDK includes the Silverlight library assembly, which is organized as the client and server library. For a list of controls in the Silverlight SDK, see controls by function category.

The following steps describe how to add a reference to the Silverlight library assembly.

Add reference to the Silverlight library assembly
  1. In"Solution resource Browser", Right-click the Silverlight project, and select"Add reference".

  2. Will display"Add reference"Dialog box.

  3. In". Net"Tab, select the reference to add.

  4. For example, you will select system. Windows. Controls. Data to use the DataGrid Control in the project.

  5. Click"OK".

  6. The reference you added is displayed in the reference node.

Note:

To exclude the referenced assembly from the application package, select the Assembly reference and"Attribute"In the window"Copy local"Set to false. This method is useful if you want to retrieve an assembly as needed. For more information, see the topic of the application structure.

To use an assembly in XAML, you must specify the XML namespace ing.

Add XML namespace ing
  1. Open mainpage. XAML.

  2. In the <usercontrol> start tag, add a tag to declare the namespace. For example, you will add the following tag to use the DataGrid.

    Copy
    xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
  3. To use an element in XAML, add the name specified in the XML namespace ing as the prefix for the name. For example, the DataGrid element in XAML looks like the following:

    Copy
    <sdk:DataGrid></sdk:DataGrid>

    For a list of default prefixes and mappings, see the prefixes and Mappings of the Silverlight library.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.