22// The .NET Foundation licenses this file to you under the MIT license.
33// See the LICENSE file in the project root for more information.
44
5+ using System ;
56using System . Collections . Generic ;
67using System . Linq ;
78using Windows . Foundation ;
@@ -152,7 +153,7 @@ protected override Size ArrangeOverride(Size finalSize)
152153 if ( finalSize != DesiredSize )
153154 {
154155 // We haven't received our desired size. We need to refresh the rows.
155- finalSize = UpdateRows ( finalSize ) ;
156+ UpdateRows ( finalSize ) ;
156157 }
157158
158159 if ( _rows . Count > 0 )
@@ -194,6 +195,7 @@ private Size UpdateRows(Size finalSize)
194195 var position = new UvMeasure ( Orientation , Padding . Left , Padding . Top ) ;
195196
196197 var currentRow = new Row ( new List < UvRect > ( ) , default ) ;
198+ var finalMeasure = new UvMeasure ( Orientation , width : 0.0 , height : 0.0 ) ;
197199 void Arrange ( UIElement child , bool isLast = false )
198200 {
199201 var desiredMeasure = new UvMeasure ( Orientation , child . DesiredSize ) ;
@@ -222,6 +224,7 @@ void Arrange(UIElement child, bool isLast = false)
222224
223225 // adjust the location for the next items
224226 position . U += desiredMeasure . U + spacingMeasure . U ;
227+ finalMeasure . U = Math . Max ( finalMeasure . U , position . U ) ;
225228 }
226229
227230 var lastIndex = Children . Count - 1 ;
@@ -241,10 +244,11 @@ void Arrange(UIElement child, bool isLast = false)
241244 return Size . Empty ;
242245 }
243246
244- var lastRowRect = _rows . Last ( ) . Rect . ToRect ( Orientation ) ;
245- return new Size (
246- lastRowRect . Bottom + Padding . Bottom ,
247- lastRowRect . Right + Padding . Right ) ;
247+ // Get max V here before computing final rect
248+ var lastRowRect = _rows . Last ( ) . Rect ;
249+ finalMeasure . V = lastRowRect . Position . V + lastRowRect . Size . V ;
250+ var finalRect = finalMeasure . Add ( paddingEnd ) . ToSize ( Orientation ) ;
251+ return finalRect ;
248252 }
249253 }
250254}
0 commit comments