Prism Sample 22-ConfirmCancelNavigation
导航到一个视图,如果在离开这个视图时需要确认,在VM中实现以下接口
public class ViewAViewModel : BindableBase, IConfirmNavigationRequest { public ViewAViewModel() { } public void ConfirmNavigationRequest(NavigationContext navigationContext, Action<bool> continuationCallback) { bool result = true; if (MessageBox.Show("Do you to navigate?", "Navigate?", MessageBoxButton.YesNo) == MessageBoxResult.No) result = false; continuationCallback(result); } public bool IsNavigationTarget(NavigationContext navigationContext) { return true; } public void OnNavigatedFrom(NavigationContext navigationContext) { } public void OnNavigatedTo(NavigationContext navigationContext) { } }