全球禁用键盘的WPF窗口键盘、窗口、全球、WPF

2023-09-09 21:12:32 作者:菁华浮梦长

我需要禁用键盘输入的,除了一个或2例外所有UI元素。

I need to disable Keyboard Input for all UI elements except one or 2 exceptions.

事情是,我需要控制使箭头键我加了KeyEventHandler在主窗口的水平,并增加了一个用于用户界面元素,如选项卡项目,文本框,让他们忽略了输入时,他们得到了关注的焦点。 我结束了一个pretty的buggie控制。我仍然可以浏览例如通卡项目,控制活动,有时不火。我需要一个更可靠的方式来做到这一点。

Thing is, I need the arrow keys for controlling so I added a KeyEventHandler on the MainWindow level and added another for UI Elements like Tab Items, Textbox so that they ignore the Input when they got the focus. I ended up with a pretty buggie control. I still can browse e.g. thru tab items, the control event sometimes doesn't fire. I need a more reliable way to do this..

任何建议都是AP preciated!

Any suggestions are appreciated!

推荐答案

不被视为默认输入键的方向键。因此它们通过窗口上的控制仍然滚动。要改变这种情况,您可以订阅 previewKeyDown 事件(的http://msdn.microsoft.com/en-us/library/system.windows.uielement.$p$pviewkeydown.aspx)并设置 previewKeyDownEventArgs.IsInputKey = TRUE; ,见http://msdn.microsoft.com/en-us/library/system.windows.forms.$p$pviewkeydowneventargs.isinputkey.aspx.然后箭头键也可以调用其他按键事件处理函数为的KeyDown

The arrow keys are not considered input keys by default. Therefore they still scroll through the controls on the window. To change this behavior you can subscribe to the PreviewKeyDown event (http://msdn.microsoft.com/en-us/library/system.windows.uielement.previewkeydown.aspx) and set PreviewKeyDownEventArgs.IsInputKey = true;, see http://msdn.microsoft.com/en-us/library/system.windows.forms.previewkeydowneventargs.isinputkey.aspx. Then the arrow keys will also invoke other key event handlers as KeyDown.

 
精彩推荐
图片推荐