Reputation: 3219
I am working on an app for WP 8.1, it uses Windows Runtime and not Silverlight. Because of this I have no access to the NavigationService
class.
I have tried to manually implement a Back Stack by pushing the current page type to the stack in the OnNavigatedTo()
method with no luck.
All I need to do is find a way to manage navigation history so that when a user hits the hardware back button they are taken to the last page in the app they were on, until the user is on the first page where hitting back would exit the application.
Can someone point me in the right direction here?
Upvotes: 1
Views: 980
Reputation: 4567
You can access the backstack via the BackStack property of your navigation frame. To do that you can simply override the GoBack command inside your NavigationHelper class (you can find it inside the Common folder). There you can simply check the BackStackDepth: if it's 0 then you can terminate the current app, as the default behaviour would suspend it without closing it :)
Something like (in the NavigationHelper class):
public virtual void GoBack()
{
if (this.Frame != null)
{
if (this.Frame.CanGoBack) this.Frame.GoBack();
else App.Current.Exit();
}
}
Upvotes: 1
Reputation: 3568
The Frame class now holds the Navigation methods (BackStack, GoBack, Navigate, etc.)
Get it via (in a Pages Codebehind):
((Frame)Parent).BackStack;
Or somewhere else via:
((Frame)Window.Current.Content).BackStack;
Upvotes: 0