It is unreasonable to roll back to the previous page. For example, if a pop-up box is opened, you may press the return key to close the pop-up box. In this case, their intention is not to leave the application. "return" only means to get rid of the pop-up dialog box. There are two methods for rewriting. The first is to override the onbackkeypress event, and the second is to override the phoneapplicationpage_backkeypress event.
The following code re-writes the return key in Windows Phone
1. Rewrite the onbackkeypress event
Protected override void onbackkeypress (system. componentmodel. canceleventargs E)
{
E. Cancel = true;
If (MessageBox. Show ("Save project ?? "," ", Messageboxbutton. okcancel) = messageboxresult. OK)
{
App. intilize ();
Navigationservice. navigate (New uri ("/mainpage. XAML", urikind. relativeorabsolute ));
}
}
2. Rewrite the phoneapplicationpage_backkeypress event.
Add event:
Rewrite:
Note that you must not forget to cancel the original return key operation, that is, do not forget E. Cancel = true.