0
如何在UWP模板10应用程序中取消导航?我们试图在ViewModel中存在未保存数据(IsDirty
)的地方取消导航。在UWP模板中取消导航10
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óthTibor Template10 1.1.12 – Vague
@TóthTibor project.json显示Template10 1.1.12。 Visual Studio扩展管理器显示模板10版本1.19。 – Vague