none
How to redirect keyboard input from a WinForm Form to a WPF user control hosted within the form via the ElementHost RRS feed

  • Question

  • How to redirect keyboard input from a WinForm Form to a WPF user control hosted within the form via the ElementHost?

    In my case I have an WinForms MDI application which hosts WPF user controls within ElementHost controls in a way that they are docked to fill the entire content of the child MDI forms. One problem that I ran accross recently is that if a user clicks on the title bar of the MDI child that keyboard events are understandably not forwarded to the internal user control which prevents  the WPF user control from being able handle these events.

    What I'm looking to do is in some form or an other use the ProcessCmdKey method or an IMessageFilter implementation to intercept windows messages specifically for keyboard related events and then forward them to the corresponding WPF user control. The difficulty that I've found is that I haven't found an adequate way to retrieve the target HWND that I can the User32 PostMessage API function and effectively forward the messages into the WPF user control.

    I do understand a little about the technical details of how WPF is drastically different from traditional windows UI in that WPF user controls do not contain an HWND themselves. So I guess what I'm looking to do is tap into the same underlaying message translation that the ElementHost provides in order to forward keyboard event messages that occur on my WinForm based Form to the hosted WPF control.

    If anybody could give me some pointers it would be greatly appreciated.

    Thursday, October 21, 2010 4:43 PM

Answers

All replies