首页 > 代码库 > asp.net项目引用silverlight插件
asp.net项目引用silverlight插件
其实很简单,silverlight4中,只需要新建一个silverlight项目,找到启动的aspx或html页面,复制引用代码到asp.net项目的aspx即可,同时在项目中引用silverlight项目下的silverlight.js.说实话.其实在这个方面现在来说两者是一样的,目前发现区别在于启动方式?silverlight需要加载一个xaml启动,asp.net则不需要,可以做到加载多个xaml的效果,从跟html兼容这方面来说,效果要比用silverlight项目好.
引用代码:
script部分:
<script type="text/javascript" src="http://www.mamicode.com/Silverlight.js"></script>
<script type="text/javascript">
function onSilverlightError(sender, args) {
var appSource = "";
if (sender != null && sender != 0) {
appSource = sender.getHost().Source;
}
var errorType = args.ErrorType;
var iErrorCode = args.ErrorCode;
if (errorType == "ImageError" ||
errorType == "MediaError") {
return;
}
var errMsg = "Unhandled Error in Silverlight Application "
+ appSource + "\n";
errMsg += "Code: " + iErrorCode + " \n";
errMsg += "Category: " + errorType + " \n";
errMsg += "Message: " + args.ErrorMessage + " \n";
if (errorType == "ParserError") {
errMsg += "File: " + args.xamlFile + " \n";
errMsg += "Line: " + args.lineNumber + " \n";
errMsg += "Position: " + args.charPosition + " \n";
}
else if (errorType == "RuntimeError") {
if (args.lineNumber != 0) {
errMsg += "Line: " + args.lineNumber + " \n";
errMsg += "Position: " + args.charPosition +
" \n";
}
errMsg += "MethodName: " + args.methodName + " \n";
}
throw new Error(errMsg);
}
</script>
布局部分:
<div id="silverlightControlHost">
<object width="50%" height="50%"
type="application/x-silverlight-2"
data="data:application/x-silverlight-2," >
<param name="source" value="http://www.mamicode.com/SilverlightApplication1.xap"/>
<param name="onerror" value="http://www.mamicode.com/onSilverlightError" />
<param name="background" value="http://www.mamicode.com/white" />
<param name="minRuntimeVersion" value="http://www.mamicode.com/4.0.50826.0" />
<param name="autoUpgrade" value="http://www.mamicode.com/true" />
<a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.60310.0"
style="text-decoration: none;">
<img
src="http://go.microsoft.com/fwlink/?LinkId=161376"
alt="Get Microsoft Silverlight"
style="border-style: none"/>
</a>
</object>
<iframe id="_sl_historyFrame"
style=‘visibility:hidden;height:0px;width:0px;border:0px‘>
</iframe>
</div>
小白一枚,欢迎讨论