Tech Off Thread

5 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Strange WPF Textbox Problem

Back to Forum: Tech Off
  • User profile image
    jh71283

        Hello All.

    I Have a WPF Textbox on a window.

    It receives keydown events, but it is not possible to change the text in the textbox.

     The Space, Backspace and delete keys work to change text that is already there, but none of the letters work( even though, as I said, the keydown events are registering ok)

    I suspect, although I don't know why, that the events are being intercepted somewhere along the line, but I am not sure how I would go about finding out where exactly.


    Can anybody give me a nudge in the right direction?

  • User profile image
    KAE

    http://forums.microsoft.com/msdn/showpost.aspx?postid=1104593&siteid=1

    "Proper input interop with a non-WPF host (such as WinForms) requires some cooperation between the host and the WPF input system. The topic Sharing Message Loops Between Win32 and WPF  in the SDK explains this well. At a minimum, you have to call ComponentDispatcher.RaiseThreadMessage() from the host’s message loop. In your setup, the easiest way to make this happen is to use code like this:

       Window w = new Window1();

       System.Windows.Forms.Integration.ElementHost.EnableModelessKeyboardInterop(w);

       w.Show();

     

    ElementHost.EnableModelessKeyboardInterop() essentially registers an input hook with the WinForms Application object (which normally runs the message loop) and calls ComponentDispatcher.RaiseThreadMessage()."

  • User profile image
    jh71283

    Wow that's spooky - I've just started looking into this again this morning, after leaving it alone for months!

    You, my friend are a superstar, cos this has solved the problem outright Smiley

  • User profile image
    Eric Rasmussen

    KAE said:

    http://forums.microsoft.com/msdn/showpost.aspx?postid=1104593&siteid=1

    "Proper input interop with a non-WPF host (such as WinForms) requires some cooperation between the host and the WPF input system. The topic Sharing Message Loops Between Win32 and WPF  in the SDK explains this well. At a minimum, you have to call ComponentDispatcher.RaiseThreadMessage() from the host’s message loop. In your setup, the easiest way to make this happen is to use code like this:

       Window w = new Window1();

       System.Windows.Forms.Integration.ElementHost.EnableModelessKeyboardInterop(w);

       w.Show();

     

    ElementHost.EnableModelessKeyboardInterop() essentially registers an input hook with the WinForms Application object (which normally runs the message loop) and calls ComponentDispatcher.RaiseThreadMessage()."

    You are a rock star! I can't believe I missed this until now. I have 3-4 Wpf windows that I developed outside of my WinForms project and then moved into the project. I just spotted this problem after 2 months and spent a sleepless night troubleshooting to no avail.
    You have saved me much aggravation!
    Thanks much

  • User profile image
    andrew.geer

    KAE said:

    http://forums.microsoft.com/msdn/showpost.aspx?postid=1104593&siteid=1

    "Proper input interop with a non-WPF host (such as WinForms) requires some cooperation between the host and the WPF input system. The topic Sharing Message Loops Between Win32 and WPF  in the SDK explains this well. At a minimum, you have to call ComponentDispatcher.RaiseThreadMessage() from the host’s message loop. In your setup, the easiest way to make this happen is to use code like this:

       Window w = new Window1();

       System.Windows.Forms.Integration.ElementHost.EnableModelessKeyboardInterop(w);

       w.Show();

     

    ElementHost.EnableModelessKeyboardInterop() essentially registers an input hook with the WinForms Application object (which normally runs the message loop) and calls ComponentDispatcher.RaiseThreadMessage()."

    Thanks, KAE! I was Google-ing this issue for quite a while. I knew I should have searched for "Strange WPF Textbox Problem" Smiley

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.