From 13e1445764a6506865ccefd51a096347ec85bd19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Manuel=20Nieto=20=28SuperJMN=29?= Date: Thu, 28 Nov 2024 12:45:28 +0100 Subject: [PATCH] Fix WrapPanel when ItemWidth < Available Size --- src/Avalonia.Controls/WrapPanel.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Avalonia.Controls/WrapPanel.cs b/src/Avalonia.Controls/WrapPanel.cs index 1d6c78260d0..3c85adf1d31 100644 --- a/src/Avalonia.Controls/WrapPanel.cs +++ b/src/Avalonia.Controls/WrapPanel.cs @@ -140,7 +140,7 @@ protected override Size MeasureOverride(Size constraint) var childConstraint = new Size( itemWidthSet ? itemWidth : constraint.Width, itemHeightSet ? itemHeight : constraint.Height); - + for (int i = 0, count = children.Count; i < count; i++) { var child = children[i]; @@ -213,14 +213,18 @@ protected override Size ArrangeOverride(Size finalSize) if (MathUtilities.GreaterThan(sz.U, uvFinalSize.U)) // The element is wider then the constraint - give it a separate line { // Switch to next line which only contain one element - ArrangeLine(accumulatedV, sz.V, i, ++i, useItemU, itemU); + ArrangeLine(accumulatedV, sz.V, i, i + 1, useItemU, itemU); accumulatedV += sz.V; curLineSize = new UVSize(orientation); + firstInLine = i + 1; + } + else + { + firstInLine = i; } - firstInLine = i; } - else // Continue to accumulate a line + else // Continue to accumulate in the current line { curLineSize.U += sz.U; curLineSize.V = Max(sz.V, curLineSize.V);