0

我是银光新手。对不起,如果这是一个简单的问题。

我正在尝试在 VS2010 中使用 Silverlight 4 创建一个示例应用程序。在 aspx 页面中由 defualt 生成的代码是(除了脚本):

<div id="silverlightControlHost">
    <object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
      <param name="source" value="ClientBin/test.xap"/>
      <param name="onError" value="onSilverlightError" />
      <param name="background" value="white" />
      <param name="minRuntimeVersion" value="3.0.40624.0" />
      <param name="autoUpgrade" value="true" />
      <a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=3.0.40624.0" style="text-decoration:none">
          <img src="http://go.microsoft.com/fwlink/?LinkId=108181" 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>

我想使用 asp:silverlight 标签,所以我添加了 dll System.Web.Silverlight.dll (v2.0)。

我得到了标签,并将上面的代码替换为:

<asp:ScriptManager ID="ScriptManager1" runat="server" ></asp:ScriptManager>
<asp1:Silverlight ID="test" runat = "server" Source="~/ClientBin/test.xap">
</asp1:Silverlight>   

现在上面的代码(自己生成的)可以工作,但是asp:silverlight显示空白屏幕。

另外,另一个问题,如果我们有 2 个或更多 xaml 文件,如何调用它们?(当我们引用一个 xap 文件时,在哪里提到程序应该引用哪个 xaml 文件)

提前致谢。

4

2 回答 2

1

我认为 asp:Silverlight 标签已被贬低,我会选择生成的标签。对于其他 xaml 文件,您必须以某种方式将它们包含在 MainPage.xaml 中,方法是导航到它们或显示它们。

于 2010-10-27T22:27:37.153 回答
0

坚持使用<object>标签来定义您的 Silverlight 应用程序,因为 @Alex 提到旧的 Silverlight 服务器控件已被弃用 - 它所做的只是object为您呈现标签,并且可能不会声明您需要的所有参数。object使用时,在渲染页面上右键->查看源码,看看和手动使用标签有什么区别。

为了在 SL 应用程序中显示特定的 xaml 页面,我将假设显示哪个页面的选择取决于应用程序外部发生的操作。在这种情况下,有几种选择。您可以使用 javascript 在 SL 应用程序中调用托管代码函数,该函数可以显示相应的页面。您可以从 SL 应用程序调用回包含页面 - 您可以调用 javascript 函数或访问页面上的 HTML 元素。或者,您可以将信息作为 SL 应用程序的一部分传递InitParams

<param name="InitParams" value="<% =GetMyInitParams() %>" />

在aspx页面后面的代码中:

protected string GetMyInitParams()
{
    return "MyStartPage=Page1,SomeOtherParam=blah";
}

这些 InitParams 可作为您StartupEventArgsApplication_StartupSL 应用程序使用:

    private void Application_Startup(object sender, StartupEventArgs e)
    {
        if (e.InitParams != null && e.InitParams.Count > 0)
        {
            foreach (string key in e.InitParams.Keys)
            {
                switch (key)
                {
                    case "MyStartPage":
                        myPageToShow = e.InitParams["MyStartPage"];
                        break;
                }
            }
        }
        this.RootVisual = new MainPage();
    }
于 2010-10-27T22:45:47.250 回答