WindowsFormsHost1.Child.Can't Focus RRS feed

  • Question

  • In a WPF control I have a hosted WinFormUserControl control via a WindowsFormsHost

    Now, in the WPF control code I do:

      void ShowWinFormUserControl()
        windowsFormsHost1.Visibility = System.Windows.Visibility.Visible;
        bool success;
        success = windowsFormsHost1.Focus();    // true
        success = windowsFormsHost1.Child.Focus(); // false
        success = windowsFormsHost1.Child.CanFocus; // false
        windowsFormsHost1.Select(); // any effect if first display
        // _arretSelection is the windowsFormsHost1.Child
        this._arretSelection.Select(); // any effect if first display

    Why? How do I force focus on the WinFormsHost child?

    Difference between the situation when the windowsFormsHost is still hidden 

    or already visible 

    Best regards, Sergiu
    Tuesday, November 23, 2010 10:56 AM


  • Hi Sergui Dudnic,

    You can use Dispatcher.BeginInvoke method to focus it after it is displayed.

    windowsFormsHost1.Dispatcher.BeginInvoke(new Action(() => windowsFormsHost1.Child.Focus()), DispatcherPriority.Background);

    Hope this helps.

    If you still have any doubts or concerns about this issue, please feel free to let me know.

    Best regards,


    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
    • Marked as answer by Sergiu Dudnic Sunday, November 28, 2010 6:01 PM
    Friday, November 26, 2010 9:55 AM