Window Focus issue with .NET 4.0 and WindowsFormstHost

I get strange behavior that I'm having problems with:

  • Add a simple Forms control using the text box for WindowsFormsHost;
  • Add a button that will open another WPF Window (not establishing an owner);
  • Expand the original WPF window and click on the text box so that it focuses;
  • When you do this, then try activating another WPF window from the taskbar is activated and then deactivated.

What worries is that if I compile this in .NET 3.5, this is not a problem.

Any ideas?

+8
winforms wpf wpf-controls
source share
1 answer

Implementing this in a derived window helps a little - but does not completely solve the problem:

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 the focus on the window when deactivating - this is not early enough, so the activation leans back, but when you press Alt-Tab a second time, it switches. However, concentrated management is not maintained. I tried adjusting the focus, but nothing good.

+1
source share

Source: https://habr.com/ru/post/650731/


All Articles