diff --git a/src/Avalonia.Controls/Window.cs b/src/Avalonia.Controls/Window.cs index 3c3841031f7..b2c9ebd9864 100644 --- a/src/Avalonia.Controls/Window.cs +++ b/src/Avalonia.Controls/Window.cs @@ -93,6 +93,7 @@ public class Window : WindowBase, IFocusScope, ILayoutRoot private bool _isExtendedIntoWindowDecorations; private Thickness _windowDecorationMargin; private Thickness _offScreenMargin; + private bool _canHandleResized = false; /// /// Defines the property. @@ -722,6 +723,8 @@ private void ShowCore(Window? owner) // 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 @@ public Task ShowDialog(Window owner) // 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 @@ private protected sealed override void HandleClosed() /// 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;