我想在等待未完成时按“返回”按钮或任何导航事件来阻止更改当前页面。因为那时异常发生,它应该显示在同一页面上,另一种情况下很难理解什么动作会产生这种异常
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
}
答案 0 :(得分:1)
您可以使用以下方法截取后退按钮:
protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs e)
{
e.Cancel = true;
}
显然你可以在那里做任何你想做的事。