0
votes

How to cancel navigation in a UWP Template 10 app? We are trying to cancel navigation where there is unsaved data (IsDirty) in the 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;
    }

However navigation is not cancelled. Navigation can be cancelled if we omit the dialog. How do cancel navigation away from the ViewModel in response to a dialog?

1
Which version of T10 do you use? - Tóth Tibor
@Tóth Tibor Template10 1.1.12 - Vague
@Tóth Tibor project.json shows Template10 1.1.12. Visual Studio Extension Manager shows Template 10 version 1.19. - Vague

1 Answers

0
votes

Someone had the same issue than you. https://github.com/Windows-XAML/Template10/issues/1307

It's resolved in the 1.1.13 (preview) version. So you need to update the nuget package.