我有一个消息对话框,显示两个按钮nav-to-page1和nav-to-page2按钮,意味着我限制用户导航到page1或page2。
我遇到一个问题,万一打开消息对话框,按回按钮,按此行为关闭我的消息对话框。
我可以在消息对话框未打开时覆盖后退按钮。当对话框打开时,我想覆盖后退按钮。
MessageDialog dlg = new MessageDialog("Are you sure you want to quit you will loose all your work ?", "Warning");
dlg.Commands.Add(new UICommand("nav-to-page1", new UICommandInvokedHandler(CommandHandler1)));
dlg.Commands.Add(new UICommand("nav-to-page2", new UICommandInvokedHandler(CommandHandler1)));
await dlg.ShowAsync();
非常感谢任何帮助
答案 0 :(得分:0)
默认情况下,关闭Backkeypress上的messagedialog。不要认为你可以覆盖这种行为,因为它在messagedialog打开时没有点击backkeypress方法。一个建议:现在当您按下后退按钮时,它将其作为命令并进入“CommandHandler1”方法。要在创建命令时避免这种情况,请添加一些命令ID,如
private async void gv_Tapped(object sender, TappedRoutedEventArgs e)
{
GridView gvi = sender as GridView;
MessageDialog dlg = new MessageDialog("Are you sure you want to quit you will loose all your work ?", "Warning");
dlg.Commands.Add(new UICommand("nav-to-page1", new UICommandInvokedHandler(CommandHandler1), 0));
dlg.Commands.Add(new UICommand("nav-to-page2", new UICommandInvokedHandler(CommandHandler1),1));
await dlg.ShowAsync();
}
private void CommandHandler1(IUICommand command)
{
// throw new NotImplementedException();
}