我的 wpf 应用程序中有一个模式弹出窗口。显示该窗口后,在某些(极少数)情况下,该窗口会从 UI 中消失。但是我们可以发现,使用“alt + tab”并不能使其处于活动状态。
请在下面找到我使用的代码,
//WindowInteropHelper assists interoperation between Windows Presentation Foundation (WPF) and Win32 code.
private void OnControlClick(object sender, RoutedEventArgs e)
{
System.Drawing.Point p = System.Windows.Forms.Control.MousePosition;
MyPopup popup = new MyPopup();
_windowInteropHelper = new System.Windows.Interop.WindowInteropHelper(popup);
_windowInteropHelper.Owner = this._owner;
popup.WindowStartupLocation = System.Windows.WindowStartupLocation.Manual;
popup.Left = p.X;
popup.Top = p.Y;
popup.Closing += new System.ComponentModel.CancelEventHandler(OnPopupClosing);
popup.ShowDialog();
}