应用启动时,基于变量重定向到某些页面

时间:2012-11-16 09:29:28

标签: c# windows-phone-7 xaml

  

可能重复:
  How to change startup page on WP7 application

默认情况下,当您的应用启动时,Windows Phone应用会导航到“MainPage.xaml”。如何通过基于某些变量重定向到其他页面来干预这一点。

例如,如果var a为true,则转到page1.xaml,否则转到page2.xaml ...

感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

我将做的是这个app.xaml.cs文件`

    private void Application_Launching(object sender, LaunchingEventArgs e)
    {
        SetupDefautPage();
    }

    private void Application_Activated(object sender, ActivatedEventArgs e)
    {            
        SetupDefautPage();
    }`

和我的虚空SetupDefautPage看起来像这样:

 void SetupDefautPage()
    {
        if ((DefaultPage !=false)&&(DefaultPage !=true)) 
        {
            (Application.Current as App).DefaultPage = false;
        }

        if (DefaultPage==false)
         {
            ((App)Application.Current).RootFrame.Navigate(new Uri("/TermUsePage.xaml", UriKind.Relative));
         }
        else if(DefaultPage==true)
         {
           ((App)Application.Current).RootFrame.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
         }


    }

这只是一个想法,我希望这对你有好处