使用 OnNavigatingFrom 確認導航請求

private bool navigateFlag = false;

protected async override void OnNavigatingFrom(NavigatingCancelEventArgs e)
{
    base.OnNavigatingFrom(e);

    if (!navigateFlag)
        {
            e.Cancel = true;

            var dialog = new MessageDialog("Navigate away?", Confir,);
            dialog.Commands.Add(new UICommand("Yes", null, 0));
            dialog.Commands.Add(new UICommand("No", null, 1);

            dialog.CancelCommandIndex = 1;
            dialog.DefaultCommandIndex = 0;

            var result = await dialog.ShowAsync();

            if (Convert.ToInt16(result.Id) != 1)
            {
                navigateFlag= true;
                this.Frame.Navigate(e.SourcePageType);
            }
           
        }

    }