How to programmatically set the start page in Windows Phone 8?

I want to set the start page in a Windows Phone 8 application programmatically after checking some data in config. What event can I use to do the same?

Thanx in advance.

+4
source share
3 answers

I used Application_Launching for one task. Something like that:

    private void Application_Launching(object sender, LaunchingEventArgs e)
    {
        RootFrame.Navigated += RootFrame_Navigated;
        var logined = Singleton.Instance.User.Load();
        var navigatingUri = logined ? "/View/PageMainPanorama.xaml" : "/View/Account/PageLoginRegister.xaml";
        ((App)Current).RootFrame.Navigate(new Uri(navigatingUri, UriKind.Relative));
    }
+6
source

The first step is to remove the default page that we set by default in the manifest file (WMAppManifest.xml) in applications created from standard templates.

Just remove NavigationPage = "MainPage.xaml" from the code below.

<Tasks>
      <DefaultTask Name="_default" NavigationPage="MainPage.xaml" />
</Tasks>

InitializePhoneApplication(), RootFrame.Navigate() ( App.xaml.cs).

private void InitializePhoneApplication()
        {
            if (phoneApplicationInitialized)
                return;

            // Create the frame but don't set it as RootVisual yet; this allows the splash
            // screen to remain active until the application is ready to render.
            RootFrame = new PhoneApplicationFrame();
            RootFrame.Navigated += CompleteInitializePhoneApplication;

            // Handle navigation failures
            RootFrame.NavigationFailed += RootFrame_NavigationFailed;

            // Handle reset requests for clearing the backstack
            RootFrame.Navigated += CheckForResetNavigation;

            // Ensure we don't initialize again
            phoneApplicationInitialized = true;

            Uri uri;
            if (IsolatedStorageSettings.ApplicationSettings.Contains("islogin"))
            {
                if (!(Convert.ToString(IsolatedStorageSettings.ApplicationSettings["islogin"]).ToLower() == "yes"))
                {
                    RootFrame.Navigate(new Uri("/LoginScreen.xaml", UriKind.RelativeOrAbsolute));
                }
                else
                {
                    RootFrame.Navigate(new Uri("/HomeScreen.xaml", UriKind.RelativeOrAbsolute));               
                }
            }
            else
            {
                RootFrame.Navigate(new Uri("/LoginScreen.xaml", UriKind.RelativeOrAbsolute));
            }          
        }
+2

Here you can find a blog entry that describes how to dynamically configure the homepage.

http://blogs.msdn.com/b/ptorr/archive/2010/08/28/redirecting-an-initial-navigation.aspx?wa=wsignin1.0

+1
source

Source: https://habr.com/ru/post/1530196/


All Articles