From f0226b70fe2d084e1f6ee5f0cea2b87d013344b6 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Wed, 5 Jun 2024 02:52:49 +0200 Subject: [PATCH] Use the owner window's screen as the constraint. (#15910) #14982 added some logic from WPF to contrain a window showed with `WindowStartupLocation.CenterOwner` to the screen, but it had a bug: the screen used was the screen that the window being _shown) is currently on, not the _owner_ window. This means that if the owner window is on a different screen to the window being shown then it will be constrained to the wrong screen. You can see this on Windows by showing a child `Window` with `CenterOwner` when the owner window is on a secondary screen: the child window will initially be shown on the primary screen and so the constraint will be wrong, resulting in the child window being shown on the wrong screen. --- src/Avalonia.Controls/Window.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Avalonia.Controls/Window.cs b/src/Avalonia.Controls/Window.cs index a3c70d5b82..bbaed03dd4 100644 --- a/src/Avalonia.Controls/Window.cs +++ b/src/Avalonia.Controls/Window.cs @@ -976,7 +976,7 @@ namespace Avalonia.Controls PixelSize.FromSize(ownerSize, scaling)); var childRect = ownerRect.CenterRect(rect); - if (Screens.ScreenFromWindow(this)?.WorkingArea is { } constraint) + if (Screens.ScreenFromWindow(owner)?.WorkingArea is { } constraint) { var maxX = constraint.Right - rect.Width; var maxY = constraint.Bottom - rect.Height;