Set start page in Windows Phone 8.1 universal app

依然范特西╮ 提交于 2019-12-08 05:48:51

问题


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


回答1:


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


来源:https://stackoverflow.com/questions/26755314/set-start-page-in-windows-phone-8-1-universal-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!