PreviewKeyDown 不会触发 ElementHost 中的 Tab 键和箭头键 [英] PreviewKeyDown not firing for Tab and Arrow keys in ElementHost

查看:40
本文介绍了PreviewKeyDown 不会触发 ElementHost 中的 Tab 键和箭头键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Winforms ElementHost 中有一个 WPF 窗口.KeyDown 和 PreviewKeyDown 事件不会为我的窗口上的 Tab 键和箭头键触发.

I have a WPF window in a Winforms ElementHost. The KeyDown and PreviewKeyDown events are not firing for the Tab and arrow keys on my Window.

KeyUp 和 PreviewKeyUp 似乎工作正常,对于大多数其他键来说,PreviewKeyDown 也是如此,例如:A-Z、0-9

KeyUp and PreviewKeyUp seem to work fine, as does PreviewKeyDown for most other keys, like: A-Z, 0-9

推荐答案

问题是我的窗口是从 Winforms 应用程序打开的.ElementHost.EnableModelessKeyboardInterop() 方法解决了我的问题.

The problem was that my Window was opened from a Winforms application. The ElementHost.EnableModelessKeyboardInterop() method solved my problem.

var myWindow = new MyWindow();
ElementHost.EnableModelessKeyboardInterop(myWindow);
myWindow.Show();

这篇关于PreviewKeyDown 不会触发 ElementHost 中的 Tab 键和箭头键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆