【问题标题】:Load a silverlight to aspx page through code behind通过后面的代码将silverlight加载到aspx页面
【发布时间】:2012-10-11 02:31:53
【问题描述】:

我需要在单击该页面页面上的按钮时在 aspx 页面的一部分中加载一个 Silverlight 应用程序。一些初始化参数需要根据按钮单击时主机页面上的用户输入传递给 Silverlight 应用程序。该怎么做?

我想我需要从代码隐藏创建 silverlight 对象来设置自定义 InitParameters。知道该怎么做吗?

【问题讨论】:

    标签: c# asp.net .net silverlight


    【解决方案1】:

    延伸到here,你可以这样做:

    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);
    
    HtmlGenericControl myInputParam = new HtmlGenericControl("param");
    myOnErrorParam .Attributes["name"] = "InitParameters";
    myOnErrorParam .Attributes["value"] = "param1=Hello,param2=World";
    myHtmlObject.Controls.Add(myInputParam);
    
    this.Page.Controls.Add(myHtmlObject);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-12-26
      • 1970-01-01
      • 2019-07-14
      • 1970-01-01
      • 1970-01-01
      • 2012-03-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多