Window Focus problem with .NET 4.0 and WindowsFormstHost
I'm getting some strange behavior that I'm having trouble with:
- Add a simple Forms control with text box to a WindowsFormsHost;
- Add a button that opens another WPF Window (not setting owner);
- Maximize the original WPF window and click on the text box so it has focus;
- When you do that and then try to activate the other WPF window from the task bar it gets activated and then deactivated.
What is troubling is that if I compile this under .NET 3.5 it works no problem. 开发者_Python百科
Any ideas?
Implementing this on a derived window helps a bit - but does not solve the problem completely:
protected override void OnDeactivated(EventArgs e)
{
var host = System.Windows.Input.FocusManager.GetFocusedElement(this) as System.Windows.Forms.Integration.WindowsFormsHost;
if (host !=null )
{
Focus();
}
base.OnDeactivated(e);
}
It sets focus to the window on deactivate - this is not early enough so activation flips back, but when you alt-tab second time it switches. Focused control is not preserved though. I tried dispatching focus set - but no good.
精彩评论