设置silverlight开始页面

11 silverlight

如何在Silverlight中设置"启动"页面?不确定我是否在谷歌搜索错误的术语,或者似乎没有在任何地方提到它.

干杯

Ant*_*nes 12

术语"启动页面"有点含糊不清.在Silverlight应用程序中,您可能意味着一些事情.

要作为RootVisual加载的初始UserControl

在app.xaml.cs中,您将找到如下代码: -

    private void Application_Startup(object sender, StartupEventArgs e)
    {
        this.RootVisual = new MainPage();
    }
Run Code Online (Sandbox Code Playgroud)

MainPage用户控件在哪里是初始根视觉.你可以改变这是你自己的选择.

也许您希望将其设置RootVisual为多种可能的选择之一.在这种情况下,您需要使用InitParams.就像是:-

    private void Application_Startup(object sender, StartupEventArgs e)
    {
        Type t = Type.GetType("SilverlightApplication1." + e.InitParams["StartupPage"]);

        this.RootVisual = Activator.CreateInstance(t);
    }
Run Code Online (Sandbox Code Playgroud)

然后,您需要<object>在主机HTML 中的标记中包含InitParams值: -

 <object  ...>
   ...
   <param name="InitParams" value="StartupPage=Page1" />
 </object
Run Code Online (Sandbox Code Playgroud)

使用导航框架

如果您构建导航应用程序,则需要另一种方法.在这种情况下,MainPage将包含一个包含要映射的初始URL FrameSourceproeperty.

使用此类型的应用程序,您只需在页面的URL中添加#后面的路径即可指定要加载的备用页面.