Book Image

Windows Application Development Cookbook

By : Marcin Jamro
Book Image

Windows Application Development Cookbook

By: Marcin Jamro

Overview of this book

Need to ensure you can always create the best Windows apps regardless of platform? What you need are solutions to the biggest issues you can face, so you can always ensure you’re making the right choices and creating the best apps you can. The book starts with recipes that will help you set up the integrated development environment before you go ahead and design the user interface. You will learn how to use the MVVM design pattern together with data binding, as well as how to work with data in different file formats. Moving on, you will explore techniques to add animations and graphics to your application, and enable your solution to work with multimedia content. You will also see how to use sensors, such as an accelerometer and a compass, as well as obtain the current GPS location. You will make your application ready to work with Internet-based scenarios, such as composing e-mails or downloading files, before finally testing the project and submitting it to the Windows Store. By the end of the book, you will have a market-ready application compatible across different Windows devices, including smartphones, tablets, and desktops.
Table of Contents (17 chapters)
Windows Application Development Cookbook
Credits
About the Author
Acknowledgements
About the Reviewer
www.PacktPub.com
Preface

Changing a default page


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.

Getting ready

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.

How to do it...

To change a default page, shown when the application is launched, you need to perform the following steps:

  1. Open the App.xaml.cs file by expanding the App.xaml node in the Solution Explorer window and double-clicking on App.xaml.cs.

  2. Take the line in the OnLaunched method (line #75):

            rootFrame.Navigate(typeof(MainPage), e.Arguments); 
    

  3. Change this line to the following:

            rootFrame.Navigate(typeof(DefaultPage), e.Arguments); 
    

How it works...

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.

There's more...

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.

See also

  • The Navigating between pages recipe

  • The Passing data between pages recipe

  • The Handling the back button recipe

  • The Modifying the back stack recipe