The previous method was to force an error to crash the program. The following solution seems better.
Private void phoneapplicationpage_backkeypress (Object sender, system. componentmodel. canceleventargs e) {If (MessageBox. Show ("are you sure you want to exit the program? "," Prompt ", messageboxbutton. okcancel) = messageboxresult. OK) {navigationservice. removebackentry () ;}else {e. Cancel = true ;}}
The following is a reprinted article -----------------------------------------
In the blog Park, many people wrote how to exit the Windows Phone application. In fact, the Windows Phone program does not need to exit.
However, some children's shoes need to be studied. Some methods have been used to summarize all of them!
The following method is correct
Public static void gomainpagewithback (navigationservice, string mainpageurl)
{
While (navigationservice. cangoback)
{
Ienumerator <journalentry> List = navigationservice. backstack. getenumerator ();
List. movenext ();
Journalentry current = List. Current;
String uri = current. Source. tostring ();
If (uri = mainpageurl)
{
Navigationservice. Goback ();
}
Else
{
Navigationservice. removebackentry ();
}
}
}
The general meaning is to remove the page in your navigation stack. If it is the homepage, Goback () and then you will go out!