Yinguangzhi silverlight4.0 tutorial and learning to use frame controls

Source: Internet
Author: User
Tags visual studio 2010

Microsoft released Silverlight 4 Beta on pdc2009. Microsoft processed requests from about 8000 Silverlight end users in Silverlight 4 and added a series of exciting new features from other developers, the most prominent aspects are as follows:

Development Tool enhancement: Visual Studio 2010 has a visual design tool. When creating a project, you can choose whether the runtime version is 3.0 or 4.0. blend4 is added to the XAML and C #CodeAll-round smart sensing functions, and more easy-to-use XAML style applications.

Camera and MIC hardware support: a very small amount of code can be used to enable webcam and mic on the user's local machine, and local recording can be performed.

Report printing support: the problem of report printing is well solved in silverlight4.

More powerful basic controls (RichTextBox and DataGrid enhanced edition): Rich Text controls RichTextBox and DataGrid with the pasting and sorting functions are added.

WCF enhancement: TCP communication is finally supported, which is 3-5 times higher than HTTP, limited to ipv2-4534 ports.

Enhanced compatibility: Google Chrome browser support.

MEF support: MEF is all called the managed extensibility framework.Program.

Improved Running Speed: the startup speed and rendering speed are about two times higher than the previous version.

DRM enhancement: playready is supported, which can protect video and audio playback and supplement H.264 DRM protection.

Other enhancements: support for local file read/write, right-click event, and clipboard cutting.

 

Many friends encounter a special situation when developing a large Silverlight application. Because Silverlight runs as a plug-in HTML, a common program portal has a website, for example: http://www.abc.com/mysilverlight.aspx and so on, when the Silverlight application accidentally refreshes the browser while the user is using it, for example, if you press F5 incorrectly, click the refresh button of the browser, and the user does not respond to this type during program usage.

Next we will learn how to use the frame control in silverlight4 to create a "website homepage" for this series of tutorials ".

XAML:

     <  Grid   X : Name = "Layoutroot"  >          <  Grid. rowdefinitions  >              <  Rowdefinition  Height = "75"  />              <  Rowdefinition  />          </  Grid. rowdefinitions  >          <  Stackpanel   Grid . Row = "0"   Background = "Darkblue" >              <  Textblock   Fontsize = "24"   Margin = "5"   Foreground = "White"  > Silverlight 4 getstart </  Textblock  >              <  Textblock   Fontsize ="14"   Margin = "5"   Foreground = "White"  > Silver? How long does a open? By? Http://www.Silverlighter.net </  Textblock  >          </  Stackpanel  >          <  Grid   Grid . Row = "1"  >              <  Grid. columndefinitions  >                  <  Columndefinition   Width = "180"  />                  <  Columndefinition  />              </  Grid. columndefinitions  >             <! -- Import? Airline? -->              <  ListBox   Grid . Column = "0"   X : Name = "Controls"   Selectionchanged = "Controls_selectionchanged"  >                  <  Sys : String > Videoandaudio </  Sys : String  >                  <  Sys : String  > Richtextboxsample </  Sys : String  >                  <  Sys : String > Mousewheelsample </  Sys : String  >                  <  Sys : String  > Webbrowsersample </  Sys : String  >                  <  Sys : String > Printsample </  Sys : String  >                  <  Sys : String  > Clipboardsample </  Sys : String  >                  <  Sys : String > Compositetransformsample </  Sys : String  >                  <  Sys : String  > Filesyssample </  Sys : String  >              </  ListBox  >             <  Stackpanel   X : Name = "Content"   Margin = "10"   Grid . Column = "1"  >                  <  SDK : Frame   Name = "Frame1" />              </  Stackpanel  >          </  Grid  >      </  Grid  > 

C #:

         Void Framesample_loaded ( Object Sender, routedeventargs e) {controls. selectedindex = 0 ;} Private   Void Controls_selectionchanged (Object Sender, selectionchangedeventargs e) {ListBox box = sender As ListBox; // Note that the Assembly name sl4sample and component must be added.              String NAV =" /Sl4sample; component/ "+ Box. selecteditem. tostring () +" . XAML "; // The following line of code implements dynamic URL Modification Frame1.source = New Uri (NAV, urikind. Relative );/** The following code uses the reflection method to create usercontrol *, which is the same as using the frame control, but does not support dynamic URL * type controltype = type. getType ("sl4sample. "+ box. selecteditem. tostring (); * object control = activator. createinstance (controltype); * If (this. content. children. count> 0) * This. content. children. clear (); * This. content. children. add (control as usercontrol );*/ }

Running result:

Figure 1:

URL: http: // localhost: 3996/sl4sample. Web/sl4sampletestpage.html #/sl4sample; component/compositetransformsample. XAML

Figure 2:

Figure 3:

Http: // localhost: 3996/sl4sample. web/sl4sampletestpage.html #/sl4sample; component/compositetransformsample. in XAML, the #/sl4sample; component/compositetransformsample. XAML is the URL of a dynamic Silverlight page.

If you develop a Silverlight full-site website application, if the user refresh the browser by mistake, the entire website will return to the home page's XAML interface, instead of refreshing the current page just like an ordinary HTML website. In silverlight4, you can use the frame control to easily handle this problem, because this control can generate a complete xaml url for the URL address, even if the user refreshes the browser, the Silverlight Program maintains the current program interface, just like the HTML website.

 

I hope it will be useful to you ~

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.