diff --git a/src/Windows/Avalonia.Win32/WindowImpl.cs b/src/Windows/Avalonia.Win32/WindowImpl.cs index dfa3eff9b00..67c82655ec9 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); @@ -860,6 +862,17 @@ public void SetTopmost(bool value) _topmost = value; } + private void EnsureTopmost() + { + if(_topmost) + { + SetWindowPos(_hwnd, + WindowPosZOrder.HWND_TOPMOST, + 0, 0, 0, 0, + SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOSIZE | SetWindowPosFlags.SWP_NOACTIVATE); + } + } + public unsafe void SetFrameThemeVariant(PlatformThemeVariant themeVariant) { _currentThemeVariant = themeVariant;