我使用的示例代码Busy.xaml
显示ModalDialog
在Template10
:(UWP)使用ESC键关闭ModalDialog
public static void SetBusy(bool busy, string text = null)
{
WindowWrapper.Current().Dispatcher.Dispatch(() =>
{
var modal = Window.Current.Content as ModalDialog;
var view = modal.ModalContent as Busy;
if (view == null)
modal.ModalContent = view = new Busy();
modal.IsModal = view.IsBusy = busy;
view.BusyText = text;
modal.CanBackButtonDismiss = true;
});
}
我可以用ALT+Left Arrow
关闭此对话框,但在大多数桌面应用程序按ESC
键通常会也关闭弹出或对话框。
我尝试添加代码来处理KeyDown
Busy.xaml
,但是当我按ESC
或任何键时,此方法从未执行过。
private void UserControl_KeyDown(object sender, KeyRoutedEventArgs e)
{
if (e.Key == VirtualKey.Escape)
{
e.Handled = true;
SetBusy(false);
}
}
那么,如何使这个ModalDialog
接近时用户按ESC
键?
我已经编辑我的问题,谢谢。 –
@AskTooMuch请注意您的用例:除了处理键盘上的“转义”外,您可能还想处理XBox控制器上的“B”按钮以及手机和平板电脑等移动设备上的“硬件后退按钮”。 – Herdo
我测试过了,这些场景中的大部分都是由Template10处理的,我无法确认它是否处理XBOX上的“B”按钮,因为我没有XBOX设备来测试,但是感谢让我知道这个问题。 –