如何取消UWP模板10应用程序中的导航?我们试图取消导航,在ViewModel中有未保存的数据(ViewModel)。
public class ViewModel : ViewModelBase
{
public override async Task OnNavigatingFromAsync(NavigatingEventArgs args)
{
if (this.IsDirty)
{
ContentDialog errorDialog = new ContentDialog();
errorDialog.Title = "Save?";
errorDialog.Content = "If you continue you will lose unsaved changes";
errorDialog.PrimaryButtonText = "Cancel";
errorDialog.SecondaryButtonText = "Continue";
ContentDialogResult answer = await errorDialog.ShowAsync();
if (answer == ContentDialogResult.Primary)
args.Cancel = true;
}
await Task.CompletedTask;
}但是,导航没有被取消。如果省略对话框,导航可以取消。如何取消ViewModel的导航以响应对话框?
发布于 2017-03-13 10:42:11
有人比你有同样的问题。https://github.com/Windows-XAML/Template10/issues/1307
它在1.1.13 (预览)版本中得到解决。所以你需要更新nuget包裹。
https://stackoverflow.com/questions/42759023
复制相似问题