diff --git a/src/Shared/HandyControl_Shared/Interactivity/Commands/PushMainWindow2TopCommand.cs b/src/Shared/HandyControl_Shared/Interactivity/Commands/PushMainWindow2TopCommand.cs index 07a2427c..386d6a78 100644 --- a/src/Shared/HandyControl_Shared/Interactivity/Commands/PushMainWindow2TopCommand.cs +++ b/src/Shared/HandyControl_Shared/Interactivity/Commands/PushMainWindow2TopCommand.cs @@ -1,8 +1,7 @@ using System; using System.Windows; using System.Windows.Input; -using System.Windows.Interop; -using HandyControl.Tools.Interop; +using HandyControl.Tools; namespace HandyControl.Interactivity { @@ -15,11 +14,7 @@ namespace HandyControl.Interactivity if (Application.Current.MainWindow != null && Application.Current.MainWindow.Visibility != Visibility.Visible) { Application.Current.MainWindow.Show(); - var hwndSource = (HwndSource)PresentationSource.FromDependencyObject(Application.Current.MainWindow); - if (hwndSource != null) - { - InteropMethods.SetForegroundWindow(hwndSource.Handle); - } + WindowHelper.SetWindowToForeground(Application.Current.MainWindow); } } diff --git a/src/Shared/HandyControl_Shared/Tools/Helper/WindowHelper.cs b/src/Shared/HandyControl_Shared/Tools/Helper/WindowHelper.cs index 41436aac..fcbb36b6 100644 --- a/src/Shared/HandyControl_Shared/Tools/Helper/WindowHelper.cs +++ b/src/Shared/HandyControl_Shared/Tools/Helper/WindowHelper.cs @@ -157,15 +157,13 @@ namespace HandyControl.Tools /// 让窗口激活作为前台最上层窗口 /// /// - public static void SetWindowToForegroundWithAttachThreadInput(Window window) + public static void SetWindowToForeground(Window window) { // [WPF 让窗口激活作为前台最上层窗口的方法 - lindexi - 博客园](https://www.cnblogs.com/lindexi/p/12749671.html) var interopHelper = new WindowInteropHelper(window); - // 以下 Win32 方法可以在 https://github.com/kkwpsv/lsjutil/tree/master/Src/Lsj.Util.Win32 找到 var thisWindowThreadId = InteropMethods.GetWindowThreadProcessId(interopHelper.Handle, out _); var currentForegroundWindow = InteropMethods.GetForegroundWindow(); - var currentForegroundWindowThreadId = - InteropMethods.GetWindowThreadProcessId(currentForegroundWindow, out _); + var currentForegroundWindowThreadId = InteropMethods.GetWindowThreadProcessId(currentForegroundWindow, out _); // [c# - Bring a window to the front in WPF - Stack Overflow](https://stackoverflow.com/questions/257587/bring-a-window-to-the-front-in-wpf ) // [SetForegroundWindow的正确用法 - 子坞 - 博客园](https://www.cnblogs.com/ziwuge/archive/2012/01/06/2315342.html )