Thursday, November 18, 2010

Windows Phone 7: Use of Back Button

I recently submitted a WP7 app to the marketplace and was denied because I failed to follow one of the guidelines. You see, in order to submit an app successfully, you must meet these certification requirements. The one mistake I made is that I had a dialog box of sorts which didn't behave as it is supposed to when the back button is pressed. The back button guidelines are here...
To maintain a consistent user experience, the Back button must only be used for backwards navigation in the application.
a. Pressing the Back button from the first screen of an application must exit the application.
b. Pressing the Back button must return the application to the previous page.
c. If the current page displays a context menu or a dialog, the pressing of the Back button must close the menu or dialog and cancel the backward navigation to the previous page.
d. For games, when the Back button is pressed during gameplay, the game can choose to present a pause context menu or dialog or navigate the user to the prior menu screen. Pressing the Back button again while in a paused context menu or dialog closes the menu or dialog.

As mentioned in point "c" above, I needed to find a way to close the dialog box when the back button is pressed. The way to go about this was not immediately obvious to me. I thought that I needed to do something fancy like navigate to a URI fragment on the page to open the dialog box. That way you're actually adding something to the navigation history. But I had a lot of problems trying to get this to work.

As it turns out, this is much simpler than I originally thought. Let's say your dialog box is in a Popup control. Well all you really have to do to intercept the back button and close the Popup is this...

0 comments: