Search code examples
c#xamlwindows-phone-7windows-phone-8windows-phone

How to change start page at startup?


my application, currently, goes to the MainPage.xaml at startup (I don't know where it has configured though).

I want to be able to start with another page in some conditions. I think I can add this code to Application_Launching() in App.xaml.cs page:

NavigationService.Navigate(new Uri("/SecondPage.xaml", UriKind.Relative));

but NavigationService is not available in App.xaml.cs.

How can I start the application with another page if foo == true?


Solution

  • Changing start page in App.Xaml.cs:

    private void Application_Launching(object sender, LaunchingEventArgs e)
    {
    
            Uri nUri = new Uri("/SecondPage.xaml", UriKind.Relative);
            ((App)Application.Current).RootFrame.Navigate(nUri);
    
    }
    

    Setting static startup page in Property\WMAppManifest.xml file

    <DefaultTask  Name ="_default" NavigationPage="SecondPage.xaml"/>
    

    edit

    Try it:

        private void Application_Launching(object sender, LaunchingEventArgs e)
        {
            Uri nUri = new Uri("/GamePage.xaml", UriKind.Relative);
            RootFrame.Navigate(nUri);
        }
    

    and in Property\WMAppManifest.xml clear NavigationPage:

    <DefaultTask  Name ="_default" NavigationPage=""/>