@@ -96,64 +96,83 @@ protected override Size MeasureOverride(Size availableSize)
96
96
var parentHeight = 0.0 ;
97
97
var accumulatedWidth = Padding . Left + Padding . Right ;
98
98
var accumulatedHeight = Padding . Top + Padding . Bottom ;
99
-
99
+
100
100
var leftSpacing = false ;
101
101
var topSpacing = false ;
102
102
var rightSpacing = false ;
103
103
var bottomSpacing = false ;
104
-
105
- foreach ( var child in Children )
104
+ var childrenCount = LastChildFill ? Children . Count - 1 : Children . Count ;
105
+
106
+ for ( var index = 0 ; index < childrenCount ; ++ index )
106
107
{
108
+ var child = Children [ index ] ;
107
109
var childConstraint = new Size (
108
110
GetPositiveOrZero ( availableSize . Width - accumulatedWidth ) ,
109
111
GetPositiveOrZero ( availableSize . Height - accumulatedHeight ) ) ;
110
-
112
+
111
113
child . Measure ( childConstraint ) ;
112
114
var childDesiredSize = child . DesiredSize ;
113
-
115
+
114
116
switch ( ( Dock ) child . GetValue ( DockProperty ) )
115
117
{
116
118
case Dock . Left :
119
+ leftSpacing = true ;
120
+ parentHeight = Math . Max ( parentHeight , accumulatedHeight + childDesiredSize . Height ) ;
117
121
if ( childConstraint . Width is not 0 )
118
122
accumulatedWidth += HorizontalSpacing ;
119
- leftSpacing = true ;
120
- parentHeight = Math . Max ( parentHeight , accumulatedHeight + childDesiredSize . Height - VerticalSpacing ) ;
121
123
accumulatedWidth += childDesiredSize . Width ;
122
124
break ;
123
-
125
+
124
126
case Dock . Right :
127
+ rightSpacing = true ;
128
+ parentHeight = Math . Max ( parentHeight , accumulatedHeight + childDesiredSize . Height ) ;
125
129
if ( childConstraint . Width is not 0 )
126
130
accumulatedWidth += HorizontalSpacing ;
127
- rightSpacing = true ;
128
- parentHeight = Math . Max ( parentHeight , accumulatedHeight + childDesiredSize . Height - VerticalSpacing ) ;
129
131
accumulatedWidth += childDesiredSize . Width ;
130
132
break ;
131
-
133
+
132
134
case Dock . Top :
135
+ topSpacing = true ;
136
+ parentWidth = Math . Max ( parentWidth , accumulatedWidth + childDesiredSize . Width ) ;
133
137
if ( childConstraint . Height is not 0 )
134
138
accumulatedHeight += VerticalSpacing ;
135
- topSpacing = true ;
136
- parentWidth = Math . Max ( parentWidth , accumulatedWidth + childDesiredSize . Width - HorizontalSpacing ) ;
137
139
accumulatedHeight += childDesiredSize . Height ;
138
140
break ;
139
-
141
+
140
142
case Dock . Bottom :
143
+ bottomSpacing = true ;
144
+ parentWidth = Math . Max ( parentWidth , accumulatedWidth + childDesiredSize . Width ) ;
141
145
if ( childConstraint . Height is not 0 )
142
146
accumulatedHeight += VerticalSpacing ;
143
- bottomSpacing = true ;
144
- parentWidth = Math . Max ( parentWidth , accumulatedWidth + childDesiredSize . Width - HorizontalSpacing ) ;
145
147
accumulatedHeight += childDesiredSize . Height ;
146
148
break ;
147
149
}
148
150
}
149
-
150
- if ( leftSpacing || rightSpacing )
151
- accumulatedWidth -= HorizontalSpacing ;
152
- if ( bottomSpacing || topSpacing )
153
- accumulatedHeight -= VerticalSpacing ;
154
-
155
- parentWidth = Math . Max ( parentWidth , accumulatedWidth ) ;
156
- parentHeight = Math . Max ( parentHeight , accumulatedHeight ) ;
151
+
152
+ if ( LastChildFill )
153
+ {
154
+ var child = Children [ Children . Count - 1 ] ;
155
+ var childConstraint = new Size (
156
+ GetPositiveOrZero ( availableSize . Width - accumulatedWidth ) ,
157
+ GetPositiveOrZero ( availableSize . Height - accumulatedHeight ) ) ;
158
+
159
+ child . Measure ( childConstraint ) ;
160
+ var childDesiredSize = child . DesiredSize ;
161
+ parentHeight = Math . Max ( parentHeight , accumulatedHeight + childDesiredSize . Height ) ;
162
+ parentWidth = Math . Max ( parentWidth , accumulatedWidth + childDesiredSize . Width ) ;
163
+ accumulatedHeight += childDesiredSize . Height ;
164
+ accumulatedWidth += childDesiredSize . Width ;
165
+ }
166
+ else
167
+ {
168
+ if ( leftSpacing || rightSpacing )
169
+ accumulatedWidth -= HorizontalSpacing ;
170
+ if ( bottomSpacing || topSpacing )
171
+ accumulatedHeight -= VerticalSpacing ;
172
+ }
173
+
174
+ parentWidth = Math . Min ( availableSize . Width , Math . Max ( parentWidth , accumulatedWidth ) ) ;
175
+ parentHeight = Math . Min ( availableSize . Height , Math . Max ( parentHeight , accumulatedHeight ) ) ;
157
176
return new Size ( parentWidth , parentHeight ) ;
158
177
}
159
178
0 commit comments