From 2ae162838cfc5b4f75c43e39123750dcd26e6ed3 Mon Sep 17 00:00:00 2001 From: Lubomir Tetak <50887170+ltetak@users.noreply.github.com> Date: Sat, 20 Apr 2024 02:18:17 +0200 Subject: [PATCH] Multi-Monitor DPI scaling breaks dialog sizes (#15304) * Multi-Monitor DPI scaling breaks dialog sizes * move the flag up * second location --- src/Avalonia.Controls/Window.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Avalonia.Controls/Window.cs b/src/Avalonia.Controls/Window.cs index 3c3841031f..b2c9ebd986 100644 --- a/src/Avalonia.Controls/Window.cs +++ b/src/Avalonia.Controls/Window.cs @@ -93,6 +93,7 @@ namespace Avalonia.Controls private bool _isExtendedIntoWindowDecorations; private Thickness _windowDecorationMargin; private Thickness _offScreenMargin; + private bool _canHandleResized = false; /// /// Defines the property. @@ -722,6 +723,8 @@ namespace Avalonia.Controls // thus we ought to call it again later to center window correctly if needed, when scaling will be already applied SetWindowStartupLocation(owner); + _canHandleResized = true; + var initialSize = new Size( double.IsNaN(Width) ? Math.Max(MinWidth, ClientSize.Width) : Width, double.IsNaN(Height) ? Math.Max(MinHeight, ClientSize.Height) : Height); @@ -800,6 +803,8 @@ namespace Avalonia.Controls // determined only by calling this method. But here it will calculate not precise location because scaling may not yet be applied (see i.e. X11Window), // thus we ought to call it again later to center window correctly if needed, when scaling will be already applied SetWindowStartupLocation(owner); + + _canHandleResized = true; var initialSize = new Size( double.IsNaN(Width) ? ClientSize.Width : Width, @@ -1036,7 +1041,7 @@ namespace Avalonia.Controls /// internal override void HandleResized(Size clientSize, WindowResizeReason reason) { - if (ClientSize != clientSize || double.IsNaN(Width) || double.IsNaN(Height)) + if (_canHandleResized && (ClientSize != clientSize || double.IsNaN(Width) || double.IsNaN(Height))) { var sizeToContent = SizeToContent;