I have UserControl which is hoseted in ElementHost
.
It contains DataGrid
When user presses enter or double clicks the row new window is shown (modalless), and when that window is closed window with ElementHost is activated back. The problem is that DataGrid loses focus.
Snoop showed me that visual tree has the following structure:
AdornerDecorator -> AvalonAdapter -> My UserControl.
Snoop shows that after activation AdornerDecorator has properties
IsFocusable = false
IsFocused = false
IsKeyboardFocused = true
IsKeyboardFocusWithin = true
What is an absolute nonsense to me.
When user hits Tab or arrow keys the first enabled UserControl's element receives focus.
I've read this post and I'm not happy with it:
Focus works differently for WPF and Windows Forms, and there were some
rough edges around here that we were unable to fix. If you have focus
inside a WindowsFormsHost and either minimize/restore the form or show
a modal dialog, the focus inside the WindowsFormsHost may be lost –
the WindowsFormsHost still has focus, but the control inside it may
not.
Now what? Relax and be happy?
And the very disapointing is inability to reproduce the problem in other applications.
Can anyone explain what are the reasons of such a strange behavior?
May be offer some workaround.