Skip to content

Commit 513b76c

Browse files
committed
Fix #2780
External Dialogs not visible with MainWindow set to IgnoreTaskbarOnMaximize
1 parent ddf1864 commit 513b76c

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/MahApps.Metro/MahApps.Metro.Shared/Behaviours/BorderlessWindowBehavior.cs

+9-6
Original file line numberDiff line numberDiff line change
@@ -368,12 +368,15 @@ private void HandleMaximize()
368368
var width = rect.Width;
369369
var height = rect.Height;
370370

371-
// Z-Order would only get refreshed/reflected if clicking the
372-
// the titlebar (as opposed to other parts of the external
373-
// window) unless I first set the window to HWND_BOTTOM then HWND_TOP before HWND_NOTOPMOST
374-
UnsafeNativeMethods.SetWindowPos(this.handle, Constants.HWND_BOTTOM, left, top, width, height, Constants.TOPMOST_FLAGS);
375-
UnsafeNativeMethods.SetWindowPos(this.handle, Constants.HWND_TOP, left, top, width, height, Constants.TOPMOST_FLAGS);
376-
UnsafeNativeMethods.SetWindowPos(this.handle, Constants.HWND_NOTOPMOST, left, top, width, height, Constants.TOPMOST_FLAGS);
371+
// #2780 Don't blindly set the Z-Order to HWWND_NOTOPMOST. If this window has an owner, set
372+
// the Z-Order to be after the owner. This keeps external dialogs appearing correctly above
373+
// their owner window even when owner window is maximized and ignoring taskbar.
374+
IntPtr hwndInsAfter = Constants.HWND_NOTOPMOST;
375+
if (this.AssociatedObject.Owner != null)
376+
{
377+
hwndInsAfter = new WindowInteropHelper(this.AssociatedObject.Owner).Handle;
378+
}
379+
UnsafeNativeMethods.SetWindowPos(this.handle, hwndInsAfter, left, top, width, height, 0x0040);
377380
}
378381
}
379382

0 commit comments

Comments
 (0)