Very asp.net: Using the ASP.net control to encapsulate Silverlight

Source: Internet
Author: User

Many asp.net developers around the world want to know how to integrate Silverlighttm into their applications and where to integrate them into their applications. Obviously, the answer to this question is not so easy, because there are a variety of approaches to be used. You can take the entire page as a Silverlight control and perform any action on this page, or you can determine the part of the Silverlight action on the page and integrate the UI elements where many UI elements are more visible, and you are more likely to adopt the latter approach.

Sometimes the latter method is called "adding colorful islands" on the page. With Silverlight, these islands may be linked to the surrounding content by scripting methods and events.

In this month's column, I'll look at ways to build custom server controls that encapsulate Silverlight content. Encapsulating the Silverlight content into a custom ASP.net control has several advantages that make it a highly focused technology. This technology makes the integrated Silverlight content as simple as using any other server-side control, greatly increasing the chance of adoption. Adding handlers, setting properties, and calling methods on a Silverlight control is exactly the same as the process on any other control. And this approach preserves the simplicity of the page and is not affected by chaotic Silverlight-specific JavaScript, which can be easily maintained and deployed.

Using Silverlight

Before detailing the generation of custom controls to host Silverlight content, you should first describe what you need to present the Silverlight content to your customers. So in the beginning, I'll show you how to host a XAML file on a asp.net page and add interactivity between the page and the Silverlight content that is rendered. After my page shows the behavior that will eventually be encapsulated by the control, you will have a clearer idea of how to combine the parts of the control.

The first step is to write a XAML file for Silverlight rendering. My goal is to make the XAML as simple as possible when rendering the control, not fancy, and to make it content enough to arouse the reader's interest. So I chose to render a single sphere with a caption. The XAML shown in Figure 1 defines a TextBlock that is used as a caption and an ellipse drawn with a light gradient brush. This XAML also defines two Storyboard in the Canvas resource section, drawing two animations to make the sphere larger and smaller, each lasting two seconds. Finally, I want to host this XAML in Silverlight, and then, when the user clicks on the rendered sphere, use the JavaScript handler to set the caption text and invoke the animation.

Figure 1 Sphere.xaml File

<!--File:Sphere.xaml--> <canvas xmlns= "http://schemas.microsoft.com/client/2007" xmlns:x= . Microsoft.com/winfx/2006/xaml "Width=" "height=" background= "white" > <Canvas.Resources> <sto Ryboard x:name= "Growanimation" > <doubleanimation storyboard.targetname= "Ellipse" Storyboard.targetpropert Y= "(ellipse.width)" to= "duration=" 0:0:2 "/> <doubleanimation" storyboard.targetname= "Ellipse" Sto Ryboard. Targetproperty= "(ellipse.height)" to= "duration=" 0:0:2 "/> </Storyboard> <storyboard x:name=" Shrin 
    Kanimation "> <doubleanimation storyboard.targetname=" Ellipse "storyboard.targetproperty=" (Ellipse.Width) " to= "duration=" "0:0:2"/> <doubleanimation storyboard.targetname= "Ellipse" Storyboard.targetprope  Rty= "(ellipse.height)" to= "duration=" 0:0:2 "/> </Storyboard> </Canvas.Resources> <textblock X:name= "TitletexT "width=" height= "canvas.left=" "text=" [Title] "textwrapping=" Wrap "/> <ellipse" width= "" height= " "X:name=" "Ellipse" canvas.left= "canvas.top=" "<radialgradientbrush" > <Ellipse.Fill> gradientor Igin= "0.75,0.25" center= "0.5,0.5" radiusx= "0.5" radiusy= "0.5" > <gradientstop color= "yellow" offset= "0"/&gt
    ;
<gradientstop color= "Green" offset= "1"/> </RadialGradientBrush> </Ellipse.Fill> </Ellipse> </Canvas>

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.