Introduction
The default start page for an application is set in WMAppManifest.xml - in the DefaultTask node of theNavigationPage tag. While having a static start page is ideal for some apps, there are many cases where it is useful to be able to dynamically select the start page.
For example, it is often useful to have:
- a different start page for when user login credentials are stored from when they are not stored
- a "wizard" start sequence for the first time the user activates the app
The article shows how to change the remove the default page and dynamically set the new start page in C# code. It uses the context of an app which has different screens for logging in (Login.xaml) and for when they have already entered their details (HomeScreen.xaml).
Note: It is also possible to have a default page which dynamically configures itself. While this may be suitable in many cases, usually it is better for code maintenance to have separate pages.
Removing the default page
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.
Set the Start Page / View after the App has initialised
The start page is specified in InitializePhoneApplication() by calling RootFrame.Navigate() (after other initialisation has completed).
The example below shows a different start page being selected based on a check of the application settings to determine if login information has already been stored (Login status is checked with IsolatedStorageSettings.ApplicationSettings.Contains("islogin").)