Silverlight – 02 :The first Silverlight Application

来源:互联网 发布:linux reset nic 编辑:程序博客网 时间:2024/06/01 15:35

You can use vs2010 or Expression Blend to create Silverlight projects or modify existing projects.A Silverlight application project is created by using the Silverlight Application project template. Use the following steps to create a new Silverlight application project.

 
  1. Start Visual Studio 2010.On the File menu, click New and then Project. The New Project dialog box appears.In the Installed Templates pane, expand the Visual C# or the Visual Basic node and select Silverlight. In the list of templates, select Silverlight Application. The following illustration shows an example of the Silverlight project templates.Silverlight Project Templates

  2. Specify a name and a location for the application and then click OK.The New Silverlight Application dialog box appears as shown in the following illustration.

    New Silverlight Application dialog box

  3. Select a method for hosting your Silverlight application.Uncheck the Host the Silverlight application in a new Web site check box if you do not want to use a Web site to host your Silverlight application. Instead, an HTML test page will be generated to host your application.

  4. Check the Host the Silverlight application in a new Web site check box if you want to add a separate ASP.NET Web site or ASP.NET Web Application Project to your solution to host the Silverlight application. If you select this option, you must also specify the New Web project name and New Web Project Type.

  5. From the Silverlight Version drop-down list, select the version of Silverlight that you want to target.Click the OK button.
    To build the Silverlight application project, in the Build menu, click Build Solution.
    To debug the Silverlight application project, in the Debug menu, click Start Debugging.
    To run the Silverlight application project, in the Debug menu, click Start Without Debugging.

    Silverlight Application Project Files
    A Silverlight application project contains the following configuration, assembly references, and code files:
    AppManifest.xml : This is the application manifest file that is required to generate the application package. You must not edit this file.
    AssemblyInfo.cs or AssemblyInfo.vb : This file contains the name and version metadata that is embedded into the generated assembly.
    .xap file : This is the Silverlight application package. It is generated when the Silverlight application project is built. An application package is a compressed zip file that has a .xap file extension and contains all the files that you need to start your application. For more information about a Silverlight application package, see Application Structure.

    A Silverlight application project contains references to the following assemblies:
    mscorlib.dll
    System.dll
    System.Core.dll
    System.Net.dll
    System.Windows.dll
    System.Windows.Browser.dll
    System.Xml.dll

    MainPage files : The MainPage class is used to create the user interface for the Silverlight application. The MainPage class derives from UserControl. You can implement the MainPage class by using MainPage.xaml for XAML markup and MainPage.xaml.cs or MainPage.xaml.vb for the code-behind.

    App files : The App class is required by a Silverlight application to display the application user interface. The App class is implemented by using App.xaml and App.xaml.cs or App.xaml.vb. The App class is instantiated by the Silverlight plug-in after the application package (.xap file) is created.

    Test Page : A single HTML page (TestPage.html) is generated to host your application if you do not check the Host the Silverlight application in a new Web site check box in the New Silverlight Application dialog box.