diff --git a/src/Avalonia.Layout/WrapLayout.cs b/src/Avalonia.Layout/WrapLayout.cs index f95e754df9..4fc8035e8e 100644 --- a/src/Avalonia.Layout/WrapLayout.cs +++ b/src/Avalonia.Layout/WrapLayout.cs @@ -18,7 +18,6 @@ namespace Avalonia.Layout /// public class WrapLayout : VirtualizingLayout { - /// /// Gets or sets a uniform Horizontal distance (in pixels) between items when is set to Horizontal, /// or between columns of items when is set to Vertical. @@ -150,7 +149,7 @@ namespace Avalonia.Layout { bool measured = false; WrapItem item = state.GetItemAt(i); - //if (item.Measure == null) + if (item.Measure == null) { item.Element = context.GetOrCreateElementAt(i); item.Element.Measure(availableSize); @@ -164,7 +163,7 @@ namespace Avalonia.Layout continue; // ignore collapsed items } - //if (item.Position == null) + if (item.Position == null) { if (parentMeasure.U < position.U + currentMeasure.U) { @@ -206,8 +205,25 @@ namespace Avalonia.Layout // Always measure elements that are within the bounds item.Element = context.GetOrCreateElementAt(i); item.Element.Measure(availableSize); - item.Measure = new UvMeasure(Orientation, item.Element.DesiredSize.Width, item.Element.DesiredSize.Height); - currentMeasure = item.Measure.Value; + + currentMeasure = new UvMeasure(Orientation, item.Element.DesiredSize.Width, item.Element.DesiredSize.Height); + if (currentMeasure.Equals(item.Measure) == false) + { + // this item changed size; we need to recalculate layout for everything after this + state.RemoveFromIndex(i + 1); + item.Measure = currentMeasure; + + // did the change make it go into the new row? + if (parentMeasure.U < position.U + currentMeasure.U) + { + // New Row + position.U = 0; + position.V += currentV + spacingMeasure.V; + currentV = 0; + } + + item.Position = position; + } } position.U += currentMeasure.U + spacingMeasure.U; @@ -266,7 +282,7 @@ namespace Avalonia.Layout if (((position.V + desiredMeasure.V) >= realizationBounds.VMin) && (position.V <= realizationBounds.VMax)) { // place the item - ILayoutable child = context.GetOrCreateElementAt(item.Index); + var child = context.GetOrCreateElementAt(item.Index); if (Orientation == Orientation.Horizontal) { child.Arrange(new Rect(position.U, position.V, desiredMeasure.U, desiredMeasure.V));