如何在Silverlight中设置“启动”页面? 不确定我是否在谷歌上搜索错误的术语,或者似乎没有在任何地方提及。
干杯
答案 0 :(得分:12)
术语“启动页面”有些含糊不清。在Silverlight应用程序中,您可能意味着其中的一件事。
要作为RootVisual加载的初始UserControl
在app.xaml.cs中,你会找到如下代码: -
private void Application_Startup(object sender, StartupEventArgs e)
{
this.RootVisual = new MainPage();
}
其中MainPage
是初始根视觉的用户控件。你可以改变这是你自己的选择。
也许您想将RootVisual
设置为多个可能的选择之一。在这种情况下,您需要使用InitParams
。类似的东西: -
private void Application_Startup(object sender, StartupEventArgs e)
{
Type t = Type.GetType("SilverlightApplication1." + e.InitParams["StartupPage"]);
this.RootVisual = Activator.CreateInstance(t);
}
然后,您需要在主机HTML的<object>
标记中包含InitParams值: -
<object ...>
...
<param name="InitParams" value="StartupPage=Page1" />
</object
使用导航框架
如果您构建导航应用程序,则需要另一种方法。在这种情况下,MainPage
将包含Frame
个Source
项,其中包含要映射的初始网址。
使用此类型的应用程序,您只需在页面的网址中添加#后的路径即可指定要加载的替代页面。