R – All keys don’t work in a WPF window when it is calling from a WinForm project

windowwinformswpf

We had a big project developed in WinForm. Now I'm adding a new window to the project using WPF. The WPF window is now part of the project, i.e. it is not a seperate project or dll. What happened now is any control that is supposed to accept key inputs, such as textbox, does not respond to my keyboard input. The window only responds to mouse.

If I create another WPF project and call this window, all keys work!

Does anyone know the reason for this? Any work around? Thanks!

Best Answer

When creating your WPF window from your Winforms code, be sure to use ElementHost.EnableModelessKeyboardInterop to allow WPF input to work.

Example:

Window window = new Window1();
ElementHost.EnableModelessKeyboardInterop(window);
window.Show();
Related Topic