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:

NavigationService.Navigate( 
   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.

Share

About Jesse Liberty

Jesse Liberty is a Master Consultant for Falafel Software, and has three decades of experience writing and delivering software projects. He is the author of 2 dozen books and multiple Pluralsight courses, and has been a Technical Evangelist for Telerik and for Microsoft, a Distinguished Software Engineer for AT&T, a VP for Information Services for Citibank and a Software Architect for PBS.
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. Bill says:

    Thanks Jesse – straight to the point and worked 100%

    :-D

  2. Pingback: Windows Phone Fundamentals – Navigation – www.nalli.net

  3. Pingback: Anonymous

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>