• Home
  • Documentation
  • Learn
Show / Hide Table of Contents
  • Introduction
  • Getting Started
    • Download and Setup Prism
    • NuGet Packages
    • Productivity Tools
  • Commanding
  • Composite Commands
  • Event Aggregator
  • ViewModelLocator
  • WPF
    • Introduction
    • Initializing
    • Managing-Dependencies
    • Modules
    • Implementing-MVVM
    • Advanced-MVVM
    • Composing-the-UI
    • Navigation
    • Communication
    • Deploying
    • Appendix-A-Glossary
    • Appendix-B-Patterns
    • Appendix-C-Prism-Library
    • Appendix-D-Extending-Prism
    • Appendix-E-Click-Once
  • Xamarin.Forms
    • Create Your First App
    • Navigation
      • Navigation Basics
      • Passing Parameters
      • Confirming Navigation
      • Deep Linking
      • Working w/ MasterDetailPages
      • Working w/ NavigationPages
      • Working w/ TabbedPages
      • XAML Navigation
    • Application Lifecycle
    • Page Lifecycle
    • Page Dialog Service
    • EventToCommandBehavior

Confirming Navigaton

A ViewModel can determine whether or not it can perform a navigation operation. When a ViewModel implements the IConfirmNavigation or the IConfirmNavigationAsync interface, the navigation process looks to see what the result of this method is. If true, a navigation process can be invoked, meaning a call to NavigationService.NavigateAsync("target") can be made. If false, the ViewModel cannot invoke the navigation process.

IConfirmNavigation

public class ContactPageViewModel : IConfirmNavigation 
{
  public bool CanNavigate(NavigationParameters parameters)
  {
    return true;
  }
}

IConfirmNavigationAsync

public class ContactPageViewModel : IConfirmNavigationAsync
{
  public Task<bool> CanNavigateAsync(INavigationParameters parameters)
  {
    return _pageDialogService.DisplayAlertAsync("Save", "Would you like to save?", "Save", "Cancel");
  }
}
  • Edit on GitHub
  • Ask questions
  • Follow @PrismLib
  • Follow @BrianLagunas
  • Follow @DanJSiegel
Back to top Copyright 2017 Prism