Derik Whittaker

Syndication

News


Performing Back Navigation w/out adding a page to the Back Stack in WP7

In a previous post (here) I wrote about how you can catch the back button action on WP7.  In this post I will explain how you can use the NavigationService provider in WP7 to correctly navigate back to a calling page in order to remove a existing page from the back stack in order to prevent the user from going back to the page.

Below is a pretty simple sample work flow.  You go from the home page, to a second page and then back to the home page.  The item we want to discuss is how we go from the second page back to the home page.

image

Option #1 – Navigate from the SecondPage.xaml to the MainPage.xaml using NaviagationService.Navigate()

One way to perform navigation is to utilize the NavigationService and simply use Navigate and provide the URI to navigate to.  See blow for an example

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

The issue with this approach is that you are now creating a new page on the Navigation Stack.  This means that if the user hits the back button on the phone they will be routed back to the SecondPage.xaml.

Option #2 – Navigate from the SecondPage.xaml to the MainPage.xaml using the NavigationService.GoBack()

When you use the NavigationService provider to perform back navigation using the GoBack() you do not add a new page to the stack, this is a GOOD thing.  This means that if the user hits the back button on the MainPage.xaml they will NOT be routed back to the SecondPage.xaml again. 

if ( NavigationService.CanGoBack )
{
    NavigationService.GoBack();
}

There is ONE potential issue with using the .GoBack() feature and that is that if you are not 100% sure of the page you were coming from you may actually be routed back to another page or even another application.

As you can see you can use the NavigationService provider to your advantage w/ little effort.

Till next time.


Posted 09-03-2010 6:39 PM by Derik Whittaker
Filed under: ,

[Advertisement]

Comments

Alberto Silva wrote Windows Phone 7–Experiência para programadores, XXXVII
on 09-06-2010 7:39 PM

Windows Phone 7 is pulling in to the platform blogs.msdn.com/.../windows

viagra wrote re: Performing Back Navigation w/out adding a page to the Back Stack in WP7
on 09-12-2010 1:13 PM

NoyhAB  <a href="http://hcanxs.com/ ">ZjeBiAk</a>

alexg802 wrote re: Performing Back Navigation w/out adding a page to the Back Stack in WP7
on 09-13-2010 1:09 AM

Very nice site! <a href="yieopxa.com/.../1.html">is it yours too</a>

alexa500 wrote re: Performing Back Navigation w/out adding a page to the Back Stack in WP7
on 09-22-2010 5:23 AM

Very nice site! <a href="oieypxa.com/.../1.html">is it yours too</a>

About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Subscribe
Google Reader or Homepage

del.icio.us CodeBetter.com Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl CodeBetter.com Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of Devlicio.us
Red-Gate Tools For SQL and .NET

NDepend

SlickEdit
 
SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
LiteAccounting.Com
DevExpress
Fixx
NHibernate Profiler
Unfuddle
Balsamiq Mockups
Scrumy
JetBrains - ReSharper
Umbraco
NServiceBus
RavenDb
Web Sequence Diagrams
Ducksboard<-- NEW Friend!

 



Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers

 

Community Server (Commercial Edition)