Here's the scenario for my page navigation:
MainPage (MP) <==> Locations (L) <==> AddLocation (AL)
I don't want the user to ever go to AddLocation when hitting the back button on the phone.
If they are on MP and they hit back, they should exit the app.
If they went MP->L and hit back, they should go to MainPage.
If they went MP->L->AL and hit back, they should go to Locations.
If they went MP->L->AL->L and hit back, they should go to MainPage and not back to AddLocations.
Right not, I have the standard nav helpers in the Common folder and then I've added this code to the Locations page to make this happen:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
this.navigationHelper.OnNavigatedTo(e);
var bs = Frame.BackStack.Where(b => b.SourcePageType.Name == "MainPage").FirstOrDefault();
if (bs!= null)
{
Frame.BackStack.Clear();
Frame.BackStack.Add(bs);
}
}
This seems to be a terrible hack to me and I'm sure there some supported/designed way to do this that I don't know about. I'm very new to WinRT and Xaml.