Silverlight-(2) The first Silverlight Program

Source: Internet
Author: User
First open vs2008 and create a new project, "file-> New-> project ...". If the vs plug-in of Silverlight has been installed, you can find the Silverlight Project template.

Silverlight application is an empty template, while Silverlight navigation application is a template containing the basic framework. To avoid starting from 0, select the second and then OK. Vs will pop up a dialog box asking if you want to create a web site for testing. By default, continue OK.

After creating a project, check the project structure.

We can see that vs actually creates a Silverlight app project and a web site to test the Silverlight app. The purpose of this website is to help us observe the actual effect of the Silverlight app in the browser. F5 .... See the results.

Basically one lineCodeNo need to write a SilverlightProgramOK. Forget it. You can't be so lazy. Just analyze it ..

 

1. After ctrol + Shift + B is compiled, A silverlightapplication1.xap is added to the clientbin directory of the website. This xap file is the Silverlight program we see in the browser. Like Flash SWF, it is also placed in HTML through the <Object> label ..

 

<Object Data = "data: Application/x-silverlight-2, "type =" application/x-silverlight-2 "width =" 100% "Height =" 100% "> <Param name =" Source "value =" clientbin/silverlightapplication1.xap "/> <Param name =" onerror "value =" onsilverlighterror "/> <Param name =" background "value =" white "/> <Param name =" minruntimeversion "value =" 3.0.40624.0 "/> <Param name = "autoupgrade" value = "true"/> <a href = "http://go.microsoft. COM/fwlink /? Linkid = 149156 & V = 3.0.40624.0 "style =" text-Decoration: none ">  </a> </Object>

2. In addition, xapis actually a zip file. You can modify the extension of xapto to. Zip and open the ZIP file. It can be seen that it is actually composed of an XML manifest file and a group of DLL files used by Silverlight.

3. Think about how to run Silverlight. When the client sends a request to the page containing the Silverlight program, this. xap will be downloaded to the client and then run in the Silverlight runtime. Therefore, the client browser must install the Silverlight plug-in. This is the same as Flash Player installation. As for the method that compares Nb points, I can't say it. I will try it later.

 

Well, add some code below to get a hello World.

1. Open views/home. XAML and add a button.

 
<Button content = "Click me" X: Name = "mybutton" fontsize = "18" width = "150" Height = "45" Click = "mybutton_click"> </button>

2. Right-click mybutton_click to jump to the button's Click Event Processing Function

 
Private void mybutton_click (Object sender, routedeventargs e) {headertext. Text = "Hello world! ";}

3. f5 .... View results

Yes! Firefox also supports this!

 

Let's talk about some feelings about Silverlight programming.

1. The navigation template provides something similar to masterpage.

2. Apart from the syntax, writing a XAML is similar to writing An ASPX... Controls, markup, events...

3. style is also written in the XAML file, and the syntax is a little bloated, not as good as CSS.

Well, let's write so much. Later we will record more ideas, experiences, and experiences about Silverlight development.

 

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.