-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating
Windows Application Development Cookbook
By :
By default, the automatically added page is shown after you launch the application. However, you may want to start with another page. Of course, such a change is possible and does not require significant modifications. You will learn how to do it in this recipe.
To step through this recipe, you need a project with two pages, represented by the MainPage and DefaultPage classes. Of course, you should manually add the second one.
To change a default page, shown when the application is launched, you need to perform the following steps:
App.xaml.cs file by expanding the App.xaml node in the Solution Explorer window and double-clicking on App.xaml.cs.OnLaunched method (line #75):rootFrame.Navigate(typeof(MainPage), e.Arguments);
rootFrame.Navigate(typeof(DefaultPage), e.Arguments);
Changing the default page requires a small modification in the App.xaml.cs file, in the part related to the launching of the application. As you can see, such a part also uses the Navigate method (on the Frame instance), so changing the default page requires just a modification of its first parameter.
It is also possible to conditionally change the default page, for instance, depending on a value that indicates whether the user is currently logged in. The exemplary line of code is shown as follows:
rootFrame.Navigate(isLogged ? typeof(UserPage) :
typeof(AnonymousPage), e.Arguments);
In this example, if the user is logged in (isLogged equals to true), the user will be navigated to UserPage. Otherwise, AnonymousPage is used instead.