When you are navigating from one page to another in an Windows Phone App, there might be a scenario where you want to get a confirmation message from the user and act based on it . If the user is ok with it , then the navigation might continue or else we might have to cancel the navigation.
You can implement this kind of logic in the
OnNavigatingFrom event that provides the
NavigatingCancelEventArgs and includes properties like Cancel,Uri etc.
You can use the cancel property of the
NavigatingCancelEventArgs to cancel the navigation.
Using the code
Below is a sample source code demonstrating How to Cancel the Navigation in Windows Phone Programatically.
public partial class MainPage : PhoneApplicationPage
protected override void OnNavigatingFrom(System.Windows.Navigation.NavigatingCancelEventArgs e)
if (MessageBox.Show("You are about to Navigate to a Different Page . Do you want to continue ?", "Confirmation", MessageBoxButton.OKCancel)== MessageBoxResult.Cancel)
e.Cancel = true;
private void hyperlinkButton1_Click(object sender, RoutedEventArgs e)
private void button1_Click(object sender, RoutedEventArgs e)
NavigationService.Source = new Uri("/Page1.xaml", UriKind.Relative);