WP7 Development Tip of the Day: Good Manners and the Back Button

by brad 14. September 2010 06:00

By now, everyone following Windows Phone 7 knows that each phone has three prominent hardware buttons: Back, Start, and Search.  The Back button is special though, in that your application can listen for it’s use and execute code in response.

   1: <phone:PhoneApplicationPage 
   2:     x:Class="WindowsPhoneApplication1.MainPage"
   3:     BackKeyPress="PhoneApplicationPage_BackKeyPress">

But with this power also comes responsibility.  It would be bad manners to hijack the Back button for own nefarious means.  To that end, the official Application Certification Requirements specify rules governing the use of the Back button.  The good news is that if your application does not explicitly intercept Back button presses, all of these things will just work.  For free. 

  1. When the user presses the back button, they must be returned to the previous page.
  2. If the user is on the first page of your application and they press the back button, the application must exit.
  3. If your application is displaying a dialog or context menu, pressing the back button must close the dialog or context menu.

Again, if you do not write code to intercept the Back button event, all of these rules will just work for free.  It’s only when you want to execute custom code in response to the Back button that you have to worry about making sure the rules are still being followed.

One example of a valid circumstance for executing custom code when the back button is pressed is to launch a custom animation before navigating. Can you think of any others?

Other Resources

More Tips

Tags:

Windows Phone | WP7 Tip of the Day

Comments

9/16/2010 2:39:06 AM #

pingback

Pingback from iphone-ipod-ipad.zeo.hk

Web Apps : : Silverlight Cream for September 15, 2010 — #948 - iPhone iPod iPad

iphone-ipod-ipad.zeo.hk

9/22/2010 2:38:53 PM #

JasonBSteele

I've got one - by default the WebBrowser control does not support going back through web pages. So you need to:
1. count the pages navigated to by handling the Navigated event
2 If back is clicked check that the pages > 0 and if so
        webBrowser1.NavigateToString("<html><body onLoad=\"history.go(-2);\"></body></html>");
or
webBrowser1.InvokeScript(“eval”, “history.go(-1);”),
3 decrement the page count

JasonBSteele United Kingdom

10/27/2010 5:56:35 AM #

trackback

Дайджест технических материалов #5 (Windows Phone 7)

Tools, Books, Guides Windows Phone 7 Developer Tools RTM (online installer) , ISO UI Design and Interaction

Oleksandr Krakovetskiy blog

10/27/2010 3:59:31 PM #

trackback

Archived Tip of the Day by Category

Archived Tip of the Day by Category

code badger

6/21/2011 11:31:40 AM #

pingback

Pingback from chaokuaidi.com

超快递 beta版 » Windows Phone 7 资源汇总(超全)

chaokuaidi.com

5/17/2012 10:10:54 PM #

pingback

Pingback from dancecoder.com

Windows Phone 7 资源汇总 | DanceCoder

dancecoder.com

Comments are closed

About Brad

Brad Tutterow lives in Illinois and works in Missouri. He has 12 years of experience developing web sites and Windows applications using a variety of technologies and is most excited currently about Silverlight, Windows Phone 7, Halo Reach, and Visual Studio 2010.