none
Bug in NonWPF+WPF MixApplications

    Question

  • Hi,

     

    it seems that WPF windows in non-wpf applications are buggy:

    Create a non-wpf application and add a wpf window to it, then put a simple TextBox to the wpf window.

    create a new instance of that window from a non-wpf window and call the Show() Method of the wpf window.

     

    The effect on every system in out company is that noone can write anything to that Textbox, the only keys that work are space and backspace and you can paste something to that TextBox.

     

    If you call ShowDialog instead of Show everything works great!

     

    Tested with Orcas Beta 2 and VS2005 (with WPF extensions)

     

    Greetings

    Florian Sundermann

    Tuesday, August 21, 2007 1:28 PM

Answers

  • Hi Florian,

     

    The above reply from Yi-Lun is correct that the two technologies' input architecture is quite different.  Fortunately, you can allow keyboard interop using System.Windows.Forms.Integration.  When a WPF window is opened modelessly, you have to call the EnableModelessKeyboardInterop method from ElementHost to forward all keyboard messages.  For example:

      

                Window window1 = new Window();

                ElementHost.EnableModelessKeyboardInterop(window1);

                window1.Show();

     

    For more details, please see the method's documentation at:

     

    http://msdn2.microsoft.com/en-us/library/system.windows.forms.integration.elementhost.enablemodelesskeyboardinterop.aspx

     

    Thanks,

    Ricky

    Windows Forms Integration

     

     

    Friday, August 24, 2007 11:24 PM

All replies

  • Hello, don’t create WPF Windows directly in a Windows Forms application. The work needs to be done to make those two technology interoperating is more complex than simply create a Window. You should instead create a Windows Forms Form, put an ElementHost in it, and set a WPF UserControl as the Child of the ElementHost. Basically, in your case, the two technologies’ input architecture are quite different. ElementHost has done the input mapping for you.

     

    Thursday, August 23, 2007 7:18 AM
  • Hi Florian,

     

    The above reply from Yi-Lun is correct that the two technologies' input architecture is quite different.  Fortunately, you can allow keyboard interop using System.Windows.Forms.Integration.  When a WPF window is opened modelessly, you have to call the EnableModelessKeyboardInterop method from ElementHost to forward all keyboard messages.  For example:

      

                Window window1 = new Window();

                ElementHost.EnableModelessKeyboardInterop(window1);

                window1.Show();

     

    For more details, please see the method's documentation at:

     

    http://msdn2.microsoft.com/en-us/library/system.windows.forms.integration.elementhost.enablemodelesskeyboardinterop.aspx

     

    Thanks,

    Ricky

    Windows Forms Integration

     

     

    Friday, August 24, 2007 11:24 PM
  • This seems fine for WinForms, butI am hosting the WPF controls in a Win32 window/application.

     

    So how do I accomplish the same thing in my scenario?

     

    Thanks,

    Ken

     

    Sunday, October 21, 2007 12:02 AM
  • I have a WPF UserControl that I'm embedding inside a Windows Form using ElementHost. How do I get keyboard events sent to my UserControl now? EnableModelessKeyboardInterop only takes a Window, which I don't have in this case.
    Thursday, January 10, 2008 6:23 PM
  • Swindler,

    Did you ever find a solution?

    I too have a WPF UserControl hosted within ElementHost in a child Window of a MFC application.  Now the text boxes will only accept, COPY, PASTE, DELETE, and BACKSPACE.  The system receives all of the events (KEYUP, KEYDOWN, PREVIEWKEYUP, PREVIEWKEYDOWN, but won't change the text if characters are typed.

    The TEXTCHANGED event only fires for the Delete, Paste, etc.

    Any help would be appreciated.

    Jason
    Thursday, May 07, 2009 1:43 PM