【发布时间】:2017-03-13 08:15:12
【问题描述】:
如何在 UWP Template 10 应用中取消导航?我们正在尝试取消 ViewModel 中存在未保存数据 (IsDirty) 的导航。
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 以响应对话框?
【问题讨论】:
-
你用的是哪个版本的T10?
-
@Tóth Tibor Template10 1.1.12
-
@Tóth Tibor project.json 显示 Template10 1.1.12。 Visual Studio 扩展管理器显示模板 10 版本 1.19。
标签: uwp template10