From bd5f12c93954878b18f8d27e16bfc1109f40e12e Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Wed, 8 Jun 2022 00:53:35 +0100 Subject: [PATCH] test workaround for double layout passes. --- src/Avalonia.Controls/Window.cs | 14 +++++++++++--- src/Avalonia.Layout/LayoutManager.cs | 11 ++++++++++- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/Avalonia.Controls/Window.cs b/src/Avalonia.Controls/Window.cs index ed8a86445f..b654228680 100644 --- a/src/Avalonia.Controls/Window.cs +++ b/src/Avalonia.Controls/Window.cs @@ -1012,10 +1012,18 @@ namespace Avalonia.Controls SizeToContent = sizeToContent; } - Width = clientSize.Width; - Height = clientSize.Height; + // Setting width and height queues a layout pass. + if (LayoutManager is LayoutManager m) + { + using (m.BlockQueuing()) + { + Width = clientSize.Width; + Height = clientSize.Height; - base.HandleResized(clientSize, reason); + // base.HandleResize does a layout pass. but doesnt delete the queued ones. + base.HandleResized(clientSize, reason); + } + } } /// diff --git a/src/Avalonia.Layout/LayoutManager.cs b/src/Avalonia.Layout/LayoutManager.cs index fc988a8d6c..cbaa117cb3 100644 --- a/src/Avalonia.Layout/LayoutManager.cs +++ b/src/Avalonia.Layout/LayoutManager.cs @@ -2,6 +2,7 @@ using System; using System.Buffers; using System.Collections.Generic; using System.Diagnostics; +using System.Reactive.Disposables; using Avalonia.Logging; using Avalonia.Threading; using Avalonia.VisualTree; @@ -315,9 +316,17 @@ namespace Avalonia.Layout } } + private bool _blocked; + public IDisposable BlockQueuing() + { + _blocked = true; + + return Disposable.Create(() => _blocked = false); + } + private void QueueLayoutPass() { - if (!_queued && !_running) + if (!_queued && !_running && !_blocked) { Dispatcher.UIThread.Post(_executeLayoutPass, DispatcherPriority.Layout); _queued = true;