 <p>Use <code>e.Cancel = true;</code> to cancel back navigation.</p> <p>Please correct me if I'm wrong. Your code is looking messed up. I think you last page/back page is <code>mainpage.xaml</code> and in <code>OK</code> you are again navigating to this page. If this is the case then there is no need of navigating again you can use below code.</p> <pre><code>protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e) { MessageBoxResult res = MessageBox.Show("Are you sure that you want to exit?", "", MessageBoxButton.OKCancel); if (res != MessageBoxResult.OK) { e.Cancel = true; //when pressed cancel don't go back } } </code></pre>