in ContosoApp/Views/CustomerDetailPage.xaml.cs [87:126]
protected async override void OnNavigatingFrom(NavigatingCancelEventArgs e)
{
if (ViewModel.IsModified)
{
// Cancel the navigation immediately, otherwise it will continue at the await call.
e.Cancel = true;
void resumeNavigation()
{
if (e.NavigationMode == NavigationMode.Back)
{
Frame.GoBack();
}
else
{
Frame.Navigate(e.SourcePageType, e.Parameter, e.NavigationTransitionInfo);
}
}
var saveDialog = new SaveChangesDialog() { Title = $"Save changes?" };
await saveDialog.ShowAsync();
SaveChangesDialogResult result = saveDialog.Result;
switch (result)
{
case SaveChangesDialogResult.Save:
await ViewModel.SaveAsync();
resumeNavigation();
break;
case SaveChangesDialogResult.DontSave:
await ViewModel.RevertChangesAsync();
resumeNavigation();
break;
case SaveChangesDialogResult.Cancel:
break;
}
}
base.OnNavigatingFrom(e);
}