C# – WPF TextBox Not Accepting Delete Key

c++outlooktextboxwpf

I have a WPF application embedded in a Microsoft Outlook 2003 window. Everything is working fine, except none of my TextBox controls accept the backspace key. I've done some research, and the problem exists only when my window is a child of the outlook window and not if it's another window (I injected it into firefox and it works fine, and if I put my wpf UserControl into a dialog window it also works). This seems to be the converse problem that people are reporting (textbox only accepting delete/arrow keys/etc), and this thread was somewhat informative (though did not fix my issue): WPF TextBox not accepting Input when in ElementHost in Window Forms

Here is my setup:
I create a WPF UserControl, which I then put in an ElementHost. I put that host into a Windows Forms UserControl, which gets put in another Forms UserControl, which gets put into a NativeWindow (I've tried removing some of the UserControl wrapping, but with no effect). This Native window then becomes a child of the Outlook window and gets placed where I need it to be in Outlook.

Does anyone have any idea? Maybe I need to handle the windows messages differently? I did some research and found out that Outlook gets a WM_COMMAND message when I hit the backspace key, but not when I don't hit anything else. Maybe it's interpreting the backspace key as a menu accelerator or something like that?

Thanks.

Best Solution

I found a way to get around this. I extended Outlook's WndProc and listened for the WM_COMMAND. Whenever it came up I tell my WPF UserControl system to send the backspace key to the currently keyboard focused control.

I can't seem to get WM_COMMAND to fire on any other keypress besides backspace so it's working pretty well right now.