From 77d80faec2191618cc31abd8362f1b7a2d7e5049 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Tue, 1 Mar 2022 14:08:57 +0100 Subject: [PATCH] Fall back to CenterScreen when owner is minimized. When showing a child window with `WindowStartupLocation = CenterOwner` to a minimized owner window, we were displaying the child in an invalid position. Use the WPF behavior of falling back to `CenterScreen` in this situation. Fixes #7582 --- src/Avalonia.Controls/Window.cs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/Avalonia.Controls/Window.cs b/src/Avalonia.Controls/Window.cs index e138a05c7d..305d06ec78 100644 --- a/src/Avalonia.Controls/Window.cs +++ b/src/Avalonia.Controls/Window.cs @@ -858,6 +858,17 @@ namespace Avalonia.Controls private void SetWindowStartupLocation(IWindowBaseImpl? owner = null) { + var startupLocation = WindowStartupLocation; + + if (startupLocation == WindowStartupLocation.CenterOwner && + Owner is Window ownerWindow && + ownerWindow.WindowState == WindowState.Minimized) + { + // If startup location is CenterOwner, but owner is minimized then fall back + // to CenterScreen. This behavior is consistent with WPF. + startupLocation = WindowStartupLocation.CenterScreen; + } + var scaling = owner?.DesktopScaling ?? PlatformImpl?.DesktopScaling ?? 1; // TODO: We really need non-client size here. @@ -865,7 +876,7 @@ namespace Avalonia.Controls PixelPoint.Origin, PixelSize.FromSize(ClientSize, scaling)); - if (WindowStartupLocation == WindowStartupLocation.CenterScreen) + if (startupLocation == WindowStartupLocation.CenterScreen) { var screen = Screens.ScreenFromPoint(owner?.Position ?? Position); @@ -874,7 +885,7 @@ namespace Avalonia.Controls Position = screen.WorkingArea.CenterRect(rect).Position; } } - else if (WindowStartupLocation == WindowStartupLocation.CenterOwner) + else if (startupLocation == WindowStartupLocation.CenterOwner) { if (owner != null) {