在Windows Phone 8.1上等待结果时禁止导航

时间:2014-11-25 12:49:50

标签: c# windows-phone-8.1

我想在等待未完成时按“返回”按钮或任何导航事件来阻止更改当前页面。因为那时异常发生,它应该显示在同一页面上,另一种情况下很难理解什么动作会产生这种异常

    private async void AppBarButton_Click(object sender, RoutedEventArgs e)
    {
        MessageDialog dialog = null;

        try
        {
            progressRing.IsActive = true;
            this.IsEnabled = false;
            commandBar1.IsEnabled = false;
            await GlobalVars.API.Call(CC.ChangeDate, date);
            var notify = new MessageDialog("Done");
            await notify.ShowAsync();
        }
        catch (Exception ex)
        {
            dialog = new MessageDialog(ex.Message);
        }
        finally
        {
            progressRing.IsActive = false;
            this.IsEnabled = true;
            commandBar1.IsEnabled = true;
        }
        if (dialog != null) await dialog.ShowAsync();  // must be shown in the same page
    }

1 个答案:

答案 0 :(得分:1)

您可以使用以下方法截取后退按钮:

protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
{
     e.Cancel = true;
}

显然你可以在那里做任何你想做的事。