Reputation: 25631
Is it possible to invoke a back button press from code?
I want to simulate a physical back button press from the code behind for a page.
Upvotes: 5
Views: 3234
Reputation: 1218
You can't simulate a physical back button press. What I mean is you won't be able to navigate back from the first page, i.e. exit the application. Currently the only way for a WP7 Silverlight application to exit is to throw an exception. That said, if you just want to navigate back to another page in your app NavigationService.GoBack() will do the trick as keyboardP said.
By the way, why do you need to simulate a back button press? If you want to exit the app here's a nice article by Peter Torr explaining the various ways a WP7 app can exit. He also analyses scenarios that need exit functionality and talks about what can be done instead. In general, if you have some page with an ok/cancel buttons and you want the cancel to go back or exit, you can just remove it and let the user press the back button.
Upvotes: 5