Difference in Window.Show vs ShowDialog w.r.t WPF webbrowser control


  • Hi,

    I have following situation:-

    1. A Winforms app, an existing one

    2. A newly created WPF app having a WPF window. The window has a WPF webbrowser control which points to a webpage

    3. The winform app calls the wpf window. The wpf window calls it's Show() method.

    The problem is in the above situation the webpage can't receive any special keys like Delete, ctlr+c etc, basically all the shortcut keys.

    If I run the wpf app directly it works properly. If I use ShowDialog method of the wpf window it works properly. It also works if I create a wpf application object in a winform. So I guess ShowDialog must be initializing some application level properties.

    Why is such difference between show and showdialog and what can I do to solve the above issue. I cant use showdialog or application because I wont be able to hide the window. Each time creating new window is not a solution.

    Any pointer please.

    Thursday, July 26, 2012 7:06 AM


  • Hi Marsh2012,

    Here is a similar thread which has been resolved for your reference:

    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();



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

    Hope it helps.

    Have a nice day.

    Annabella Luo[MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by Marsh2012 Friday, July 27, 2012 10:18 AM
    Friday, July 27, 2012 9:55 AM

All replies