How to handle the back button on Windows Phone 7
Posted
by David_001
on Stack Overflow
See other posts from Stack Overflow
or by David_001
Published on 2010-05-20T11:07:31Z
Indexed on
2010/05/20
11:10 UTC
Read the original article
Hit count: 791
windows-phone-7
On the windows phone 7 emulator, when the hardware back button is pressed, the default behaviour is for it to close your current application. I want to override this default behaviour so that it navigates to the previous page in my application.
After some research, it seems it should be possible to do this by overriding the OnBackKeyPress method, like so:
protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
{
// do some stuff ...
// cancel the navigation
e.Cancel = true;
}
However, clicking the back button still closes my application. Putting a breakpoint on the above method reveals that it is never called. I have another breakpoint on my application exit code, and this breakpoint is hit.
Is there something else I need to do to intercept the back button?
© Stack Overflow or respective owner