简体   繁体   中英

invoke back button press from code behind in WP7

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.

NavigationService.GoBack() will do just that.

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, ie 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM