我正在ModalDialog
使用示例代码Busy.xaml
显示Template10
:
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
key时如何关闭它?