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