@@ -38,7 +38,7 @@ protected override Size MeasureOverride(Size constraint)
3838 return new Size ( 0 , 0 ) ;
3939 }
4040
41- double spacing = Math . Max ( 0 , toolBar . ItemSpacing ) ;
41+ double spacing = Math . Max ( 0 , toolBar . Spacing ) ;
4242 var infinite = new Size ( double . PositiveInfinity , constraint . Height ) ;
4343
4444 double maxHeight = 0 ;
@@ -133,7 +133,7 @@ private static OverflowMeasureResult MeasureOverflowPass(
133133
134134 for ( int i = 0 ; i < count ; i ++ )
135135 {
136- if ( children [ i ] is null )
136+ if ( children [ i ] is not { } child || child . Visibility == Visibility . Collapsed )
137137 {
138138 continue ;
139139 }
@@ -203,7 +203,7 @@ protected override Size ArrangeOverride(Size finalSize)
203203 return ArrangeAsStack ( finalSize , spacing : 0 ) ;
204204 }
205205
206- double spacing = Math . Max ( 0 , toolBar . ItemSpacing ) ;
206+ double spacing = Math . Max ( 0 , toolBar . Spacing ) ;
207207 var generator = toolBar . ItemContainerGenerator ;
208208 double x = 0 ;
209209 double height = finalSize . Height ;
@@ -226,6 +226,12 @@ protected override Size ArrangeOverride(Size finalSize)
226226 continue ;
227227 }
228228
229+ if ( child . Visibility == Visibility . Collapsed )
230+ {
231+ child . Arrange ( new Rect ( ) ) ;
232+ continue ;
233+ }
234+
229235 if ( ! first )
230236 {
231237 x += spacing ;
@@ -320,6 +326,11 @@ private Size MeasureAsStack(Size constraint, double spacing)
320326 foreach ( UIElement child in Children )
321327 {
322328 child . Measure ( infinite ) ;
329+ if ( child . Visibility == Visibility . Collapsed )
330+ {
331+ continue ;
332+ }
333+
323334 if ( index > 0 )
324335 {
325336 width += spacing ;
@@ -339,6 +350,12 @@ private Size ArrangeAsStack(Size finalSize, double spacing)
339350 bool first = true ;
340351 foreach ( UIElement child in Children )
341352 {
353+ if ( child . Visibility == Visibility . Collapsed )
354+ {
355+ child . Arrange ( new Rect ( ) ) ;
356+ continue ;
357+ }
358+
342359 if ( ! first )
343360 {
344361 x += spacing ;
0 commit comments