From 5ef61ea9f146f12da53fb159555e33419310c2a4 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Wed, 23 Jan 2019 17:29:33 +0100 Subject: [PATCH] Cache grid child measurements by size. Previously if a control in a `Grid` was measured with two different sizes, the desired size for the first measurement was returned. This caused #2129. Fixes #2129 --- src/Avalonia.Controls/Grid.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Avalonia.Controls/Grid.cs b/src/Avalonia.Controls/Grid.cs index b51583d8b3..a4f2f1d722 100644 --- a/src/Avalonia.Controls/Grid.cs +++ b/src/Avalonia.Controls/Grid.cs @@ -272,7 +272,7 @@ namespace Avalonia.Controls // - GridLayout doesn't hold any state, so you can drag the debugger execution // arrow back to any statements and re-run them without any side-effect. - var measureCache = new Dictionary(); + var measureCache = new Dictionary<(Control, Size), Size>(); var (safeColumns, safeRows) = GetSafeColumnRows(); var columnLayout = new GridLayout(ColumnDefinitions); var rowLayout = new GridLayout(RowDefinitions); @@ -312,14 +312,14 @@ namespace Avalonia.Controls // If a child has been measured, it will just return the desired size. Size MeasureOnce(Control child, Size size) { - if (measureCache.TryGetValue(child, out var desiredSize)) + if (measureCache.TryGetValue((child, size), out var desiredSize)) { return desiredSize; } child.Measure(size); desiredSize = child.DesiredSize; - measureCache[child] = desiredSize; + measureCache[(child, size)] = desiredSize; return desiredSize; } }