@@ -445,7 +445,7 @@ protected override Size MeasureOverride(Size constraint)
445445 // appears in Auto column.
446446 //
447447
448- MeasureCellsGroup ( extData . CellGroup1 , constraint , false , false ) ;
448+ MeasureCellsGroup ( extData . CellGroup1 , false , false ) ;
449449 double rowSpacing = RowSpacing ;
450450 double columnSpacing = ColumnSpacing ;
451451 double combinedRowSpacing = RowSpacing * ( RowDefinitions . Count - 1 ) ;
@@ -458,9 +458,9 @@ protected override Size MeasureOverride(Size constraint)
458458 if ( canResolveStarsV )
459459 {
460460 if ( HasStarCellsV ) { ResolveStar ( DefinitionsV , innerAvailableSize . Height ) ; }
461- MeasureCellsGroup ( extData . CellGroup2 , innerAvailableSize , false , false ) ;
461+ MeasureCellsGroup ( extData . CellGroup2 , false , false ) ;
462462 if ( HasStarCellsU ) { ResolveStar ( DefinitionsU , innerAvailableSize . Width ) ; }
463- MeasureCellsGroup ( extData . CellGroup3 , innerAvailableSize , false , false ) ;
463+ MeasureCellsGroup ( extData . CellGroup3 , false , false ) ;
464464 }
465465 else
466466 {
@@ -470,7 +470,7 @@ protected override Size MeasureOverride(Size constraint)
470470 if ( canResolveStarsU )
471471 {
472472 if ( HasStarCellsU ) { ResolveStar ( DefinitionsU , innerAvailableSize . Width ) ; }
473- MeasureCellsGroup ( extData . CellGroup3 , innerAvailableSize , false , false ) ;
473+ MeasureCellsGroup ( extData . CellGroup3 , false , false ) ;
474474 if ( HasStarCellsV ) { ResolveStar ( DefinitionsV , innerAvailableSize . Height ) ; }
475475 }
476476 else
@@ -487,7 +487,7 @@ protected override Size MeasureOverride(Size constraint)
487487 double [ ] group2MinSizes = CacheMinSizes ( extData . CellGroup2 , false ) ;
488488 double [ ] group3MinSizes = CacheMinSizes ( extData . CellGroup3 , true ) ;
489489
490- MeasureCellsGroup ( extData . CellGroup2 , innerAvailableSize , false , true ) ;
490+ MeasureCellsGroup ( extData . CellGroup2 , false , true ) ;
491491
492492 do
493493 {
@@ -498,20 +498,20 @@ protected override Size MeasureOverride(Size constraint)
498498 }
499499
500500 if ( HasStarCellsU ) { ResolveStar ( DefinitionsU , innerAvailableSize . Width ) ; }
501- MeasureCellsGroup ( extData . CellGroup3 , innerAvailableSize , false , false ) ;
501+ MeasureCellsGroup ( extData . CellGroup3 , false , false ) ;
502502
503503 // Reset cached Group2Widths
504504 ApplyCachedMinSizes ( group2MinSizes , false ) ;
505505
506506 if ( HasStarCellsV ) { ResolveStar ( DefinitionsV , innerAvailableSize . Height ) ; }
507- MeasureCellsGroup ( extData . CellGroup2 , innerAvailableSize , cnt == c_layoutLoopMaxCount , false , out hasDesiredSizeUChanged ) ;
507+ MeasureCellsGroup ( extData . CellGroup2 , cnt == c_layoutLoopMaxCount , false , out hasDesiredSizeUChanged ) ;
508508 }
509509 while ( hasDesiredSizeUChanged && ++ cnt <= c_layoutLoopMaxCount ) ;
510510 }
511511 }
512512 }
513513
514- MeasureCellsGroup ( extData . CellGroup4 , constraint , false , false ) ;
514+ MeasureCellsGroup ( extData . CellGroup4 , false , false ) ;
515515
516516 gridDesiredSize = new Size (
517517 CalculateDesiredSize ( DefinitionsU ) + ColumnSpacing * ( DefinitionsU . Count - 1 ) ,
@@ -979,27 +979,23 @@ private void ApplyCachedMinSizes(double[] minSizes, bool isRows)
979979
980980 private void MeasureCellsGroup (
981981 int cellsHead ,
982- Size referenceSize ,
983982 bool ignoreDesiredSizeU ,
984983 bool forceInfinityV )
985984 {
986- MeasureCellsGroup ( cellsHead , referenceSize , ignoreDesiredSizeU , forceInfinityV , out _ ) ;
985+ MeasureCellsGroup ( cellsHead , ignoreDesiredSizeU , forceInfinityV , out _ ) ;
987986 }
988987
989988 /// <summary>
990989 /// Measures one group of cells.
991990 /// </summary>
992991 /// <param name="cellsHead">Head index of the cells chain.</param>
993- /// <param name="referenceSize">Reference size for spanned cells
994- /// calculations.</param>
995992 /// <param name="ignoreDesiredSizeU">When "true" cells' desired
996993 /// width is not registered in columns.</param>
997994 /// <param name="forceInfinityV">Passed through to MeasureCell.
998995 /// When "true" cells' desired height is not registered in rows.</param>
999996 /// <param name="hasDesiredSizeUChanged">When the method exits, indicates whether the desired size has changed.</param>
1000997 private void MeasureCellsGroup (
1001998 int cellsHead ,
1002- Size referenceSize ,
1003999 bool ignoreDesiredSizeU ,
10041000 bool forceInfinityV ,
10051001 out bool hasDesiredSizeUChanged )
@@ -1066,14 +1062,14 @@ private void MeasureCellsGroup(
10661062 foreach ( DictionaryEntry e in spanStore )
10671063 {
10681064 SpanKey key = ( SpanKey ) e . Key ;
1069- double requestedSize = ( double ) e . Value ! ;
1065+ double desiredSize = ( double ) e . Value ! ;
10701066
10711067 EnsureMinSizeInDefinitionRange (
10721068 key . U ? DefinitionsU : DefinitionsV ,
10731069 key . Start ,
10741070 key . Count ,
1075- requestedSize ,
1076- key . U ? referenceSize . Width : referenceSize . Height ) ;
1071+ key . U ? ColumnSpacing : RowSpacing ,
1072+ desiredSize ) ;
10771073 }
10781074 }
10791075 }
@@ -1193,8 +1189,8 @@ private static double GetMeasureSizeForRange(
11931189 measureSize +=
11941190 spacing +
11951191 ( definitions [ i ] . SizeType == LayoutTimeSizeType . Auto ?
1196- definitions [ i ] . MinSize :
1197- definitions [ i ] . MeasureSize ) ;
1192+ definitions [ i ] . MinSize :
1193+ definitions [ i ] . MeasureSize ) ;
11981194 } while ( -- i >= start ) ;
11991195
12001196 return measureSize ;
@@ -1228,20 +1224,23 @@ private static LayoutTimeSizeType GetLengthTypeForRange(
12281224 /// <summary>
12291225 /// Distributes min size back to definition array's range.
12301226 /// </summary>
1227+ /// <param name="definitions">Array of definitions to process.</param>
12311228 /// <param name="start">Start of the range.</param>
12321229 /// <param name="count">Number of items in the range.</param>
1233- /// <param name="requestedSize">Minimum size that should "fit" into the definitions range.</param>
1234- /// <param name="definitions">Definition array receiving distribution.</param>
1235- /// <param name="percentReferenceSize">Size used to resolve percentages.</param>
1230+ /// <param name="spacing"><see cref="ColumnSpacing"/> or <see cref="RowSpacing"/></param>
1231+ /// <param name="desiredSize">Minimum size that should "fit" into the definitions range.</param>
12361232 private void EnsureMinSizeInDefinitionRange (
12371233 IReadOnlyList < DefinitionBase > definitions ,
12381234 int start ,
12391235 int count ,
1240- double requestedSize ,
1241- double percentReferenceSize )
1236+ double spacing ,
1237+ double desiredSize )
12421238 {
12431239 Debug . Assert ( 1 < count && 0 <= start && ( start + count ) <= definitions . Count ) ;
12441240
1241+ // The spacing between definitions that this element spans through must not be distributed
1242+ double requestedSize = Math . Max ( ( desiredSize - spacing * ( count - 1 ) ) , 0.0 ) ;
1243+
12451244 // avoid processing when asked to distribute "0"
12461245 if ( ! MathUtilities . IsZero ( requestedSize ) )
12471246 {
0 commit comments