开发者

Window Focus problem with .NET 4.0 and WindowsFormstHost

I'm getting some strange behavior that I'm having trouble with:

  1. Add a simple Forms control with text box to a WindowsFormsHost;
  2. Add a button that opens another WPF Window (not setting owner);
  3. Maximize the original WPF window and click on the text box so it has focus;
  4. 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜