Monday, January 7, 2013

Detect (And Cancel) Windows Phone Back Key

To detect when the user presses the back key, you just have to override the OnBackKeyPress function.

Just like this:
protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
    // to cancel the event
    e.Cancel = true;
You can optionally cancel the navigation or allow it to occur.

You cancel the navigation by calling the instruction on line four.

Obviously you can code any logic to conditionally cancel the navigation.

Another use is to catch the event just to persist any information and then letting the navigation occur.

No comments:

Post a Comment