I try to use back button in Windows Phone 8.1 application. When I start the App I'm on page A. Then I go to page B - it works well, but when I go by:
A -> B -> C and click hardware back button app goes to A
also when A -> B -> C -> D and back - also go to A
I used this code to navigate:
Frame.Navigate(typeof(StartingView));
and use this code to implement hardware back button:
HardwareButtons.BackPressed += HardwareButtons_BackPressed;
Frame rootFrame = Window.Current.Content as Frame;
if (rootFrame != null && rootFrame.CanGoBack)
{
rootFrame.GoBack();
e.Handled = true;
}
on page D I list the Frame.BackStack and it looks well. Also when I create button with:
Frame.GoBack();
it goes from D -> C, but when i use the hardware one it goes to A.
Any idea?
HardwareButtons_BackPressed? Remember that this event is app-wide so subscribing in every page without unsubscription may be a bad idea. Also sete.Handeled = truebeforerootFrame.GoBack(). Check if you use beside your code NavigationHelper or there was a subscription already inApp()constructor. You may also take a look at this question. I've also added suitable tag to your question and removed tags from title (in most cases they shouldn't be there). And welcome to SO. - Romasz