Navigation in universal windows app

In this post, we will learn about using navigation in Universal Windows Applications. As for a developer, they require  navigation between pages in their application.

So, we will create an Universal Windows App in Visual studio and add another page in the solution explorer following steps below:

Go to Solution Explorer –> Right click on solution –> Add –> New Item –> Page –> Ok.

Now, after adding the new page, we will add a button to our MainPage.xaml to navigate from Main Page to the newly created page. Code for Xaml file :

Now, we will go to the .CS file of MainPage which is MainPage.xaml.cs and add the code for click event of the button added in the designer. The code for navigation to another page is as below:

Now, we are done with the navigation from one page to another. But I want to navigate back from last page to the first page. For that I need to add Back button functionality to the solution so that we can navigate back and forth within the application.

To add Back button functionality, we will open App.xaml.cs file and add the following code in the OnLoaded event, inside if ( rootFrame == null ) block :

We will add OnNavigated and  event code in the App.xaml.cs file, which is as follows:

Now, our Universal Windows Application is ready for navigation functionality both back and forth. Run the application and enjoy!