Confirming Navigation
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(INavigationParameters 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");
}
}