Add a Silverlight app to HTML

Source: Internet
Author: User
Tags silverlight microsoft website

Silverlight is a browser plugin for cross-browser, cross-client platforms that can be applied on platforms such as Windows,linux,mac. As a browser plugin, Silverlight can be easily nested in HTML pages like Flash, so let me explain how to add a Silverlight app to an HTML page.

1. First, let's take a look at VS2008 auto-generated code, create a new Silverlight app project, Html_silverlightchina, and choose to distribute the Silverlight project to a Web project when it's created. 2. After the project is created, the test document page is automatically generated in the Web project, respectively Html_silverlightchinatestpage.aspx and Html_   Silverlightchinatestpage.html, because this article is about how to add Silverlight apps to HTML, we'll focus on the html_silverlightchinatestpage.html page code. HTML code 1 <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
2 3
4 5 <title>Html_SilverlightChina</title>
6 <style type= "Text/css" >
7 html, Body {
8 height:100%;
9 Overflow:auto;
10}
Body {
padding:0;
margin:0;
14}
#silverlightControlHost {
height:100%;
Text-align:center;
18}
</style>
<script type= "Text/javascript" src= "Silverlight.js" ></script>
<script type= "Text/javascript" >
function Onsilverlighterror (sender, args) {
AppSource var = "";
if (sender! = NULL && Sender! = 0) {
AppSource = Sender.gethost (). Source;
26}
27
ErrorType var = args. ErrorType;
var ierrorcode = args. ErrorCode;
30
if (ErrorType = = "Imageerror" | | errorType = = "Mediaerror") {
return;
33}
34
var errmsg = "Unhandled Error in Silverlight application" + AppSource + "\ n";
36
PNS ErrMsg + = "Code:" + ierrorcode + "\ n";
ErrMsg + = "Category:" + errorType + "\ n";
ErrMsg + = "Message:" + args. ErrorMessage + "\ n";
40
if (ErrorType = = "ParserError") {
ErrMsg + = "File:" + args.xamlfile + "\ n";
ErrMsg + = "line:" + args.linenumber + "\ n";
ErrMsg + = "Position:" + args.charposition + "\ n";
45}
ErrorType else if (= = "RuntimeError") {
if (Args.linenumber! = 0) {
ErrMsg + = "line:" + args.linenumber + "\ n";
ErrMsg + = "Position:" + args.charposition + "\ n";
50}
Wuyi errmsg + = "MethodName:" + args.methodname + "\ n";
52}
53
The new Error (errmsg);
55}
</script>
<body>
<form id= "Form1" runat= "Server" style= "height:100%" >
<div id= "Silverlightcontrolhost" >
<object data= "data:application/x-silverlight-2," type= "Application/x-silverlight-2" width= "100%" height= "100 % ">
<param name= "source" value= "clientbin/html_silverlightchina.xap"/>
<param name= "OnError" value= "Onsilverlighterror"/>
<param name= "Background" value= "white"/>
<param name= "minRuntimeVersion" value= "3.0.40818.0"/>
<param name= "AutoUpgrade" value= "true"/>
<a href= "http://go.microsoft.com/fwlink/?LinkID=149156&v=3.0.40818.0" style= "Text-decoration:none" >

</a>
</object><iframe id= "_sl_historyframe" style= "visibility:hidden;height:0px;width:0px;border:0px" >& Lt;/iframe></div>
</form>
</body>
type= "Application/x-silverlight-2", the label is the same as the type label of Silverlight 2, I looked at the Silverlight 3 Release Note, Microsoft explains that the same label content is used for Silverlight2 app upgrade to SILVERLIGHT3 compatibility. I looked at the Silverlight Beta 2 version of the label, which istype= "Application/x-silverlight-2-b2". 1 <object data= "data:application/x-silverlight-2," type= "Application/x-silverlight-2" width= "100%" height= "100%" >
2 <param name= "source" value= "clientbin/html_silverlightchina.xap"/>
3 <param name= "OnError" value= "Onsilverlighterror"/>
4 <param name= "Background" value= "white"/>
5 <param name= "minRuntimeVersion" value= "3.0.40818.0"/>
6 <param name= "AutoUpgrade" value= "true"/>
7 <a href= "http://go.microsoft.com/fwlink/?LinkID=149156&v=3.0.40818.0" style= "Text-decoration:none" >
8
9 </a>
</object> the,<param> tag in the <Object> tab defines the Silverlight instance parameters. where "source" is a more important parameter that identifies the location of the XAP file. Sometimes, depending on your project needs, you can leave source blank and then invoke it in XAML using JavaScript code. For the arguments to object, I want to use a table to list:

Parameters Introduced
AutoUpgrade Allows developers to control whether the end user's Silverlight is automatically upgraded. Default is True
Background Set app background color, default to NULL
EnableFramerateCounter Whether the current frame rate is displayed in the browser status bar, false by default
EnableHtmlAccess Whether to allow access to the browser DOM, default to False, and true to allow Silverlight to access Web pages
Iniparams Initializes the parameter information that can be passed from the Web page to the Silverlight application, where the parameters can be obtained from the background code in Silverlight (very useful)
minRuntimeVersion Run the minimum Silverlight version of the app, in this case, the minimum version is Silverlight 3.0.40818.0
MaxFrameRate Set the maximum frame rate, which is 60 frames per second by default
OnLoad You can call a custom JavaScript function in this event
SplashScreenSource Set a XAML file as the download xap when the animation start page
Source XAP path

5. In <Object> there is a piece of code like this: <a href= "http://go.microsoft.com/fwlink/? linkid=149156&v=3.0.40818.0 "style=" Text-decoration:none ">

</a> This code is detected if the browser does not have a Silverlight client plug-in installed, a "get Silverlight" picture is displayed, prompting the user to download and install the Silverlight client. Some domestic developers think that each time to the Microsoft website download speed is too slow, you can modify the "http://go.microsoft.com/fwlink/?LinkID=149156&v=3.0.40818.0 "link to allow users to download the Silverlight client plug-in locally or by specifying a connection. Let's complete the above project, add simple code, complete the demo,I uploaded a xap file to Cnblogs, and below I use the following code to invoke it. Code 1 <object data= "data:application/x-silverlight-2," type= "Application/x-silverlight-2" width= "100%" height= "100 % ">
2 <param name= "source" value= "/jv9/html_silverlightchina.xap"/>
3 <param name= "OnError" value= "Onsilverlighterror"/>
4 <param name= "Background" value= "white"/>
5 <param name= "minRuntimeVersion" value= "3.0.40818.0"/>
6 <param name= "AutoUpgrade" value= "true"/>
7 <a href= "http://go.microsoft.com/fwlink/?LinkID=149156&v=3.0.40818.0" style= "Text-decoration:none" >
8
9 </a>
Ten </object>

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.