diff --git a/src/Avalonia.Base/Layout/LayoutManager.cs b/src/Avalonia.Base/Layout/LayoutManager.cs index fc988a8d6c..446f135c83 100644 --- a/src/Avalonia.Base/Layout/LayoutManager.cs +++ b/src/Avalonia.Base/Layout/LayoutManager.cs @@ -28,7 +28,7 @@ namespace Avalonia.Layout public LayoutManager(ILayoutRoot owner) { _owner = owner ?? throw new ArgumentNullException(nameof(owner)); - _executeLayoutPass = ExecuteLayoutPass; + _executeLayoutPass = ExecuteQueuedLayoutPass; } public virtual event EventHandler? LayoutUpdated; @@ -94,6 +94,16 @@ namespace Avalonia.Layout QueueLayoutPass(); } + private void ExecuteQueuedLayoutPass() + { + if (!_queued) + { + return; + } + + ExecuteLayoutPass(); + } + /// public virtual void ExecuteLayoutPass() { @@ -319,8 +329,8 @@ namespace Avalonia.Layout { if (!_queued && !_running) { - Dispatcher.UIThread.Post(_executeLayoutPass, DispatcherPriority.Layout); _queued = true; + Dispatcher.UIThread.Post(_executeLayoutPass, DispatcherPriority.Layout); } } diff --git a/src/Avalonia.Controls/TopLevel.cs b/src/Avalonia.Controls/TopLevel.cs index 31217c70a9..0bc4adf1b5 100644 --- a/src/Avalonia.Controls/TopLevel.cs +++ b/src/Avalonia.Controls/TopLevel.cs @@ -413,11 +413,7 @@ namespace Avalonia.Controls FrameSize = PlatformImpl!.FrameSize; Width = clientSize.Width; Height = clientSize.Height; - - // Setting ClientSize and Width / Height above caused ExecuteLayoutPass to be queued. - // Instead of explicitly calling LayoutManager.ExecuteLayoutPass here, we clear the job queue. - Dispatcher.UIThread.RunJobs(DispatcherPriority.Layout); - + LayoutManager.ExecuteLayoutPass(); Renderer?.Resized(clientSize); } diff --git a/src/Avalonia.Controls/WindowBase.cs b/src/Avalonia.Controls/WindowBase.cs index 5e827cc08f..224aeea9e9 100644 --- a/src/Avalonia.Controls/WindowBase.cs +++ b/src/Avalonia.Controls/WindowBase.cs @@ -220,11 +220,7 @@ namespace Avalonia.Controls { ClientSize = clientSize; FrameSize = PlatformImpl?.FrameSize; - - // Setting ClientSize and Width / Height above caused ExecuteLayoutPass to be queued. - // Instead of explicitly calling LayoutManager.ExecuteLayoutPass here, we clear the job queue. - Dispatcher.UIThread.RunJobs(DispatcherPriority.Layout); - + LayoutManager.ExecuteLayoutPass(); Renderer?.Resized(clientSize); }