显示消息框后快捷键不起作用
我有一个在 InputBindings 中定义了键绑定的窗口。当我将焦点设置在表单上的任何控件上时,它们第一次起作用。
但是,当显示消息框并且我按“确定”时,除非我将焦点设置在窗口中的控件上,否则快捷键不起作用。
我的输入绑定:
<Window.InputBindings>
<KeyBinding Gesture="Ctrl+N" Command="{x:Static local:MainWindow.NewMenuCommand}" />
<KeyBinding Gesture="Ctrl+O" Command="{x:Static local:MainWindow.OpenMenuCommand}" />
<KeyBinding Gesture="Ctrl+S" Command="{x:Static local:MainWindow.SaveMenuCommand}" />
<KeyBinding Gesture="Ctrl+Q" Command="{x:Static local:MainWindow.CloseMenuCommand}" />
</Window.InputBindings>
我的命令绑定:
<Window.CommandBindings>
<CommandBinding Command="{x:Static local:MainWindow.NewMenuCommand}" Executed="NewEntity" />
<CommandBinding Command="{x:Static local:MainWindow.OpenMenuCommand}" Executed="OpenEntity" />
<CommandBinding Command="{x:Static local:MainWindow.SaveMenuCommand}" Executed="SaveEntity" />
<CommandBinding Command="{x:Static local:MainWindow.CloseMenuCommand}" Executed="CloseEntity" />
</Window.CommandBindings>
I have a Window with Keybindings in InputBindings defined. They work the first time and when i set the focus on any control on the form.
But when a Messagbox is shown and I press "OK" they shortcut keys don't work until I set the focus on a control in my window.
My InputBindings:
<Window.InputBindings>
<KeyBinding Gesture="Ctrl+N" Command="{x:Static local:MainWindow.NewMenuCommand}" />
<KeyBinding Gesture="Ctrl+O" Command="{x:Static local:MainWindow.OpenMenuCommand}" />
<KeyBinding Gesture="Ctrl+S" Command="{x:Static local:MainWindow.SaveMenuCommand}" />
<KeyBinding Gesture="Ctrl+Q" Command="{x:Static local:MainWindow.CloseMenuCommand}" />
</Window.InputBindings>
My CommandBindings:
<Window.CommandBindings>
<CommandBinding Command="{x:Static local:MainWindow.NewMenuCommand}" Executed="NewEntity" />
<CommandBinding Command="{x:Static local:MainWindow.OpenMenuCommand}" Executed="OpenEntity" />
<CommandBinding Command="{x:Static local:MainWindow.SaveMenuCommand}" Executed="SaveEntity" />
<CommandBinding Command="{x:Static local:MainWindow.CloseMenuCommand}" Executed="CloseEntity" />
</Window.CommandBindings>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不久前也遇到过这个问题,它与你的窗口的焦点有关,但我实际上找到了一个黑客来解决它,就像这样 -
并且在你后面的代码中将焦点放在窗口上,像这样 -
I also faced this issue while ago, it has something to do with the focus of your window but i actually found one hack to resolve it like this -
And in your code behind put the focus on the window like this -