From a3de918f69c14a4b80ba655b9793a90ab43bc90c Mon Sep 17 00:00:00 2001 From: Emmanuel Hansen Date: Mon, 24 Jun 2024 14:36:26 +0000 Subject: [PATCH] ensure owner topmost is flag if it's topmost when showing a owned window --- src/Windows/Avalonia.Win32/WindowImpl.cs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Windows/Avalonia.Win32/WindowImpl.cs b/src/Windows/Avalonia.Win32/WindowImpl.cs index dfa3eff9b00..a7973438e8a 100644 --- a/src/Windows/Avalonia.Win32/WindowImpl.cs +++ b/src/Windows/Avalonia.Win32/WindowImpl.cs @@ -708,6 +708,8 @@ public void SetParent(IWindowImpl? parent) _hiddenWindowIsParent = parentHwnd == OffscreenParentWindow.Handle; SetWindowLongPtr(_hwnd, (int)WindowLongParam.GWL_HWNDPARENT, parentHwnd); + + (parent as WindowImpl)?.EnsureTopmost(); } public void SetEnabled(bool enable) => EnableWindow(_hwnd, enable); @@ -851,13 +853,18 @@ public void SetTopmost(bool value) return; } - IntPtr hWndInsertAfter = value ? WindowPosZOrder.HWND_TOPMOST : WindowPosZOrder.HWND_NOTOPMOST; + _topmost = value; + + EnsureTopmost(); + } + + private void EnsureTopmost() + { + IntPtr hWndInsertAfter = _topmost ? WindowPosZOrder.HWND_TOPMOST : WindowPosZOrder.HWND_NOTOPMOST; SetWindowPos(_hwnd, hWndInsertAfter, 0, 0, 0, 0, SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOSIZE | SetWindowPosFlags.SWP_NOACTIVATE); - - _topmost = value; } public unsafe void SetFrameThemeVariant(PlatformThemeVariant themeVariant)