Dynamically load Silverlight applications using JavaScript

Source: Internet
Author: User

 

I have read Silverlight unleashed and know that Silverlight. Createobject and Silverlight. createobjectex functions are available in Silverlight. js. When using these two functions instead of static <Object> labels, You can dynamically load different xap packages (different Silverlight applicationsProgram).

 

Create two Silverlight applications and a web application. The solution looks like this:

The two Silverlight applications are common, but the two xap packages under the clientbin directory of the Web application are the compiled Silverlight applications. In Web applications, Silverlight. JS is generated by vs. The Silverlight. Createobject and Silverlight. createobjectex functions are in it. First, create the silverlightlibrary. js file and add the commonly used onsilverlighterror function.

On the default aspx or HTML test page, this function is set in <Object> <param>. Now, it will be set in JavaScript.

Next, add the createsilverlight function to the silverlightlibrary. js file. This function is an encapsulation of Silverlight. createobjectex. Most of the parameter settings in this function correspond to <param> of <Object>. Source is passed in by parameters. parentelement is set to a <div> (placeholder) on the page, and background in properties is set to the background color controlled by CSS, onerror is set to the previous onsilverlighterror function.

Create the createsilverlightbyjs.htm file, and add two single-choice buttons, one button, and one seat <div> (placeholder) in the <body> area ). The Value Attribute of the single-choice button is set to the name of the xap package, and The onclick attribute of the button is set to the create function that will be added later.

In the

Running status:

That's all. Enjoy!

 

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.