(1): Create a basic Silverlight Application

Source: Internet
Author: User
Summary 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. After a project is created and Silverlight 2 beta 1 is installed, vs2008 is opened. The Create Project dialog box is displayed, and 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 creation is as follows: understanding. after the xap file is created for a Silverlight application, we will not do anything. Compile the entire solution directly. We can see that there is an additional clientbin folder in 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 and you can see that it contains some DLL files and an appmanifest. XAML: Enable terrylee again. silverlightdemo2testpage. the aspx file introduces system at the top of the page. web. silverlight assembly, supports <asp: Silverlight/> controls:
<%@ 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: after running, the effect is as follows: add a click event for the button, after you enter the event name click in the XAML Editor, press the tab key to generate an event 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, and 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 everyone has read scottgu's article and I understand it. However, for the sake of completeness of the entire series, we did some repetitive work.

This article is from the "terrylee technology column" blog, please be sure to keep this source http://terrylee.blog.51cto.com/342737/67197

This article is from 51cto. com technical blog

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.