Skip to content

Commit 2eb51b8

Browse files
committed
Merge pull request AvaloniaUI#7730 from AvaloniaUI/fixes/7582-centerowner-minimized
Fall back from CenterOwner to CenterScreen when owner window is minimized.
1 parent 84f04f4 commit 2eb51b8

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/Avalonia.Controls/Window.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -859,14 +859,25 @@ private void OnGotInputWhenDisabled()
859859

860860
private void SetWindowStartupLocation(IWindowBaseImpl owner = null)
861861
{
862+
var startupLocation = WindowStartupLocation;
863+
864+
if (startupLocation == WindowStartupLocation.CenterOwner &&
865+
Owner is Window ownerWindow &&
866+
ownerWindow.WindowState == WindowState.Minimized)
867+
{
868+
// If startup location is CenterOwner, but owner is minimized then fall back
869+
// to CenterScreen. This behavior is consistent with WPF.
870+
startupLocation = WindowStartupLocation.CenterScreen;
871+
}
872+
862873
var scaling = owner?.DesktopScaling ?? PlatformImpl?.DesktopScaling ?? 1;
863874

864875
// TODO: We really need non-client size here.
865876
var rect = new PixelRect(
866877
PixelPoint.Origin,
867878
PixelSize.FromSize(ClientSize, scaling));
868879

869-
if (WindowStartupLocation == WindowStartupLocation.CenterScreen)
880+
if (startupLocation == WindowStartupLocation.CenterScreen)
870881
{
871882
var screen = Screens.ScreenFromPoint(owner?.Position ?? Position);
872883

@@ -875,7 +886,7 @@ private void SetWindowStartupLocation(IWindowBaseImpl owner = null)
875886
Position = screen.WorkingArea.CenterRect(rect).Position;
876887
}
877888
}
878-
else if (WindowStartupLocation == WindowStartupLocation.CenterOwner)
889+
else if (startupLocation == WindowStartupLocation.CenterOwner)
879890
{
880891
if (owner != null)
881892
{

0 commit comments

Comments
 (0)