我是silverlight的新手。如果这是一个简单的问题,请原谅。
我正在尝试在VS2010中使用Silverlight4来创建一个示例应用程序。在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文件)
提前谢谢。
发布于 2010-10-28 06:45:47
坚持使用<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可作为SL应用程序的Application_Startup中的StartupEventArgs提供:
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-28 06:27:37
我认为asp:Silverlight标签被取消了,我会使用生成的标签。对于其他xaml文件,您必须以某种方式将它们包含在MainPage.xaml中,无论是导航到它们还是显示它们。
https://stackoverflow.com/questions/4038154
复制相似问题