One step to learn Silverlight 2 series (1): Create a basic Silverlight Application

Source: Internet
Author: User
Overview

The release of Silverlight 2 Beta 1 brings us a lot of surprises from Runtime and Tools, such as supporting the framework languages Visual Basic, Visual C #, IronRuby, Ironpython, A series of new features such as JSON, Web Service, WCF, and Sockets support. The one-step learning Silverlight 2 series article takes you to Silverlight 2 development quickly.

This article creates a basic Silverlight 2 Application for the first part of the series. It cannot be vulgar, starting with the simplest Hello Word.

Create a project

After Silverlight 2 Beta 1 is installed, open VS2008. The new project dialog box is displayed. The Silverlight Application Project template is displayed.

The Silverlight Application cannot run independently. In the dialog box that appears, you can choose to create an ASP. NET Web Site or Web Application Project to host the Silverlight Application.

Here we choose to create a Web Application Project. The Project structure after the creation is as follows:

Understand the. xap File

After creating a Silverlight application, we did nothing and compiled the entire solution directly. We can see that a ClientBin folder is added to the resource manager, and added a TerryLee. the file of SilverlightDemo2.xap.

This file is a standard.. NET Assembly. All the XAML identifiers and resource file fragments are included during compilation. The standard Zip compression algorithm is used to reduce the volume of files downloaded by the client. Copy the file and modify the suffix .xapas to .zip. decompress the file. You can see that it contains some dll files and an AppManifest. xaml:

Open the TerryLee. SilverlightDemo2TestPage. aspx file and introduce the System. Web. Silverlight assembly at the top of the page. The <asp: Silverlight/> control is supported:

<%@ Register Assembly="System.Web.Silverlight" Namespace="System.Web.UI.SilverlightControls"    TagPrefix="asp" %>

<Asp: Silverlight/> the control declaration is as follows. The Source attribute specifies the path of the. xap file that was just compiled:

<asp:Silverlight ID="Xaml1" runat="server"         Source="~/ClientBin/TerryLee.SilverlightDemo2.xap"         Version="2.0" Width="100%" Height="100%" />

Create a Hello Word program

Now we create a simple Hello Word Silverlight program and use the following XAML to create a simple button:

The effect after running is as follows:

To add a Click event for a button, enter the event name in the XAML editor and Click it. Then press the Tab key to generate the event processing method using the default naming method:

Open Page. xaml. after the cs file, you can see that the corresponding event processing method has been generated. Now you can use the familiar C # To compile the processing program, for example, when you click the button, we change the background color and text of the button:

private void myButton_Click(object sender, RoutedEventArgs e){    this.myButton.Content = "Clicked!";    this.myButton.Background = new SolidColorBrush(Colors.Red);}

Run the above program and click the button. The text and background color of the button have changed:

Conclusion

This article is an entry to the development of the Silverlight 2 application using Visual Studio 2008. I believe you have read ScottGu's article. However, for the sake of completeness of the entire series, we did some repetitive work.

Next article: Learn Silverlight 2 series (2) step by step: basic controls

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.