public static void ShowActivate(this Window window) { if (window.WindowState != WindowState.Normal) { window.WindowState = WindowState.Normal; } window.Activate(); }
public static void ActivateWorkaround(this Window window) { if (window is null) { throw new ArgumentNullException(nameof(window)); } // Call default Activate() anyway. window.Activate(); // Skip workaround for non-windows platforms. if (!OperatingSystem2.IsWindows) { return; } var platformImpl = window.PlatformImpl; if (ReferenceEquals(platformImpl, null)) { return; } var platformHandle = platformImpl.Handle; if (ReferenceEquals(platformHandle, null)) { return; } var handle = platformHandle.Handle; if (IntPtr.Zero == handle) { return; } try { SetForegroundWindow(handle); } catch { // ignored } }