Windows Phone Fundamentals–Navigation

Windows Phone Fundamentals

Continuing my mini-series on Windows Phone Fundamentals, begun here, this tutorial will Navigation cover the topic of navigating from one page to another.  This is one of those tasks that are wicked simple once you know how, but which are not at first obvious at all.

To see this at work, create a new Windows Phone application and name it navigation.  Open MainPage.xaml and set the ApplicationTitle to Navigation and set the PageTitle to Page 1.

Create a second page by right clicking on the project file and choosing Add –> New Item.  From the dialog box choose  Windows Phone Portrait Page and name it Page 2.xaml.  In the newly created page set the ApplicationTitle to Navigation and set the PageTitle to Page 2.

Switch back to page 1 (MainPage.xaml) and drag and drop a HyperlinkButton onto the page.  In the properties window find the Content property and change it to Page 2 and then set the NavigateUri property to /Page2.xaml. 

Switch to Page2.xaml and drag a button onto the page.  In the xaml set its content to Page 1 and set its name to Navigate.   Now let’s set up an event handler for this button’s click event.  Open Page2.xaml.cs and add the following to the constructor:

Navigate.Click += Navigate_Click;

In the stubbed out Navigate_Click method replace the exception with the following code:

   new Uri( "/MainPage.xaml", UriKind.RelativeOrAbsolute ) );

Build and run your application, you should now be able to navigate back and forth between the two pages.

About Jesse Liberty

Jesse Liberty has three decades of experience writing and delivering software projects and is the author of 2 dozen books and a couple dozen Pluralsight & LinkedIn Learning courses. He was a Senior Technical Evangelist for Microsoft, a Distinguished Software Engineer for AT&T, a VP for Information Services for Citibank and a Software Architect for PBS. He is a Xamarin Certified Mobile Developer and a Xamarin MVP and a Microsoft MVP.
This entry was posted in Essentials, Mango, Mini-Tutorial, Patterns & Skills, WindowsPhone and tagged . Bookmark the permalink.

3 Responses to Windows Phone Fundamentals–Navigation

  1. Pingback: Windows Phone Fundamentals – Navigation –

  2. Pingback: Anonymous

Comments are closed.