在后面的代码中创建silverlight 3对象

时间:2009-10-04 09:49:42

标签: asp.net silverlight silverlight-3.0

很抱歉,如果这是一个非常简单的问题,但如何从asp.net应用程序的代码中添加silverlight 3对象,即XAP?

1 个答案:

答案 0 :(得分:0)

您有两种选择。第一个意味着更多代码,但更好的“安全性”,另一个允许您添加任何自定义HTML。

所以要么使用:

HtmlGenericControl myHtmlObject = new HtmlGenericControl("object");

myHtmlObject.Attributes["data"] = "data:application/x-silverlight-2";

myHtmlObject.Attributes["type"] = "application/x-silverlight-2";

myHtmlObject.Attributes["width"] = "100%";
myHtmlObject.Attributes["height"] = "100%";
this.Page.Controls.Add(myHtmlObject);

HtmlGenericControl mySourceParam = new HtmlGenericControl("param");
mySourceParam.Attributes["name"] = "source";
mySourceParam.Attributes["value"] = "ClientBin/MySilverlightApplication.xap";
myHtmlObject.Controls.Add(mySourceParam);

HtmlGenericControl myOnErrorParam = new HtmlGenericControl("param");
myOnErrorParam .Attributes["name"] = "onError";
myOnErrorParam .Attributes["value"] = "onSilverlightError";
myHtmlObject.Controls.Add(myOnErrorParam);

// ...依此类推......

或:

LiteralControl myHtmlSnippet = new LiteralControl(
@"<object data=""data:application/x-silverlight-2,"" type=""application/x-silverlight-2"" width=""100%"" height=""100%"">
<param name=""source"" value=""ClientBin/SilverlightApplication10.xap"" />
<param name=""onError"" value=""onSilverlightError"" />

<!-- etc... -->

</object>
");

this.Page.Controls.Add(myHtmlSnippet);

    // enter code here