4

In my application, the user goes from Page A to Page B.

Is there any way to programmatically simulate the back button press? I have a button on Page B and when the user clicks it, I want to go BACK to page A. I don't want to use the NavigationService and navigate to page A, I want to go back to Page A as if the user clicked on the hardware back button. Is there any way to do that?

2 Answers 2

23

Although you say you don't want to use it, the NavigationService.GoBack method is the way to go:

if (this.NavigationService.CanGoBack)
{
    this.NavigationService.GoBack();
}
3
  • Oh yea, i didnt know this existed. What I said, was that I didnt want to use NavigationService.Navigate. The GoBack is the way to go! Thanks! Mar 1, 2013 at 13:54
  • 1
    I updated the link in the answer as the existing one pointed to the WPF method not the Windows Phone one.
    – keyboardP
    Mar 1, 2013 at 13:55
  • 2
    This code can take you back to the previous page but it doesn't actually clicks the back button. That is if you have event on BackKeyPress, it wont execute.
    – Mangesh
    Dec 16, 2014 at 7:43
0

A little addition to Michaël Hompus's answer -- on UWP both CanGoBack property and GoBack method are located in Page.Frame.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.