From 51d158dc1b1c3f27f6868407307a0ff1ce5aea14 Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Wed, 8 Jun 2022 01:39:25 +0100 Subject: [PATCH] clear layout jobs instead of explicit layout call. --- src/Avalonia.Controls/TopLevel.cs | 7 ++++++- src/Avalonia.Controls/WindowBase.cs | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Avalonia.Controls/TopLevel.cs b/src/Avalonia.Controls/TopLevel.cs index 57fb82485c..31217c70a9 100644 --- a/src/Avalonia.Controls/TopLevel.cs +++ b/src/Avalonia.Controls/TopLevel.cs @@ -13,6 +13,7 @@ using Avalonia.Media; using Avalonia.Platform; using Avalonia.Rendering; using Avalonia.Styling; +using Avalonia.Threading; using Avalonia.Utilities; using Avalonia.VisualTree; @@ -412,7 +413,11 @@ namespace Avalonia.Controls FrameSize = PlatformImpl!.FrameSize; Width = clientSize.Width; Height = clientSize.Height; - LayoutManager.ExecuteLayoutPass(); + + // 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); + Renderer?.Resized(clientSize); } diff --git a/src/Avalonia.Controls/WindowBase.cs b/src/Avalonia.Controls/WindowBase.cs index 12ba143c8a..5e827cc08f 100644 --- a/src/Avalonia.Controls/WindowBase.cs +++ b/src/Avalonia.Controls/WindowBase.cs @@ -8,6 +8,7 @@ using Avalonia.Controls.Primitives; using Avalonia.Input; using Avalonia.Layout; using Avalonia.Platform; +using Avalonia.Threading; using JetBrains.Annotations; namespace Avalonia.Controls @@ -219,7 +220,11 @@ namespace Avalonia.Controls { ClientSize = clientSize; FrameSize = PlatformImpl?.FrameSize; - LayoutManager.ExecuteLayoutPass(); + + // 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); + Renderer?.Resized(clientSize); }