Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set start page in windows phone 8 app programmatically?

I want to set a start page in my windows phone 8 app programmatically after checking some data in config. Which event I can use to do the same?

Thanx in advance.

like image 564
Vishal Jadhav Avatar asked Jan 11 '23 02:01

Vishal Jadhav


2 Answers

I used Application_Launching for same task. Something like this:

    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));
    }
like image 153
ibogolyubskiy Avatar answered Jan 26 '23 07:01

ibogolyubskiy


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

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

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

The start page is specified in InitializePhoneApplication() by calling RootFrame.Navigate() (in App.xaml.cs) .Like example below

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));
            }          
        }
like image 35
Praveen Avatar answered Jan 26 '23 06:01

Praveen