I have a wpf textbox in wpf usercontrol hosted in a winforms elementhost itself in a winforms usercontrol. (Don't laugh!) That is then being consumed by an old VB6 app using COM Interop.

I have 3 of these on a form (with an old vb6 textbox as the 4th). Here's a screen shot

Name:  Items.PNG
Views: 112
Size:  1.5 KB

As you can see above, the 2nd item has focus and you can see the edit caret.

The behaviour I am seeing is that, the first time I mouse-click into each item, the caret appears and I can edit text. However, if I then re-mouse-click into one of these nested wpf textboxes, I do not see the caret and if I type I do not see any text. If I double-click into it I do see the caret and can edit the text contents.

If I have 2 of these nested wpf controls on a .net winform project, a single mouse-click gets me the caret and I can edit the text - which is the desired behaviour. Thus I think I must be not processing the right events (to get this working with COM Interop) or perhaps not setting focus correctly.

I have a SetFocus property on my winforms usercontrol so that the focus can be set explicitly by the consuming app. This is being invoked successfully. So I've tried setting

  • .Focus(),
  • focus via the dispatcher,
  • MouseCapture/ReleaseMouseCapture of the wpf textbox (on the GotFocus/LostFocus events)
  • the Keyboard.Focus to the wpf textbox (and clearing it)


but I still don't see any edit caret in the scenario described above.

Could anyone explain what could be different between the first time I mouse-click on one of these controls and subsequent times? (I wondered if I wasn't releasing MouseCapture properly)

Why should a double-click get me to the edit mode that I want and not a single-click?

If you have other pointers as to which events I should be checking so that I can try and diagnose the problem, that would also be helpful.

Many thx