daleijn
daleijn

Reputation: 738

Set start page in Windows Phone 8.1 universal app

I need to change start page in my app depending on logged user or not. In Silverlight 8.1 version all what I need to do is delete starting page in manifest file and in App.xaml.cs:

private void Application_Launching(object sender, LaunchingEventArgs e)
        {
            Uri uriMain = new Uri("/PivotPage.xaml", UriKind.Relative);
            Uri uriLogin = new Uri("/MainPage.xaml", UriKind.Relative);

            var settings = IsolatedStorageSettings.ApplicationSettings;
            if (!settings.Contains("user_id"))
                {
                    RootFrame.Navigate(uriLogin);
                }
            else
            {
                RootFrame.Navigate(uriMain);
            }  
        }

But in universal version I can't figure out how can I do it. What I need to do to achive this in WP 8.1universal app?

EDIT: Found a duplicate Change default startup page for windows phone 8.1 app, sorry

Upvotes: 1

Views: 3895

Answers (1)

Chubosaurus Software
Chubosaurus Software

Reputation: 8161

In App.xaml.cs look for

protected override void OnLaunched(LaunchActivatedEventArgs e)
{
    // ...

    // launch codes
    // insert here

    // Ensure the current window is active
    Window.Current.Activate();
}

My launch code detects to see if they're on the Phone or not, so I have a starting page that is different for each platform

#if WINDOWS_PHONE_APP
    if (!rootFrame.Navigate(typeof(PhonePage), e.Arguments))
    {
        throw new Exception("Failed to create initial page");
    }
#endif
#if WINDOWS_APP
    if (!rootFrame.Navigate(typeof(DesktopPage), e.Arguments))
    {
        throw new Exception("Failed to create initial page");
    }       
#endif

Upvotes: 4

Related Questions