@@ -153,7 +153,12 @@ protected override Size MeasureOverride(Size availableSize)
153153 isFixed ? availableSize . Width : double . PositiveInfinity ,
154154 double . PositiveInfinity ) ;
155155 child . Measure ( childConstraint ) ;
156- maxWidth = Math . Max ( maxWidth , child . DesiredSize . Width ) ;
156+
157+ if ( height - VerticalOffset < availableSize . Height )
158+ {
159+ maxWidth = Math . Max ( maxWidth , child . DesiredSize . Width ) ;
160+ }
161+
157162 height += child . DesiredSize . Height ;
158163 }
159164
@@ -167,23 +172,32 @@ protected override Size MeasureOverride(Size availableSize)
167172 protected override Size ArrangeOverride ( Size finalSize )
168173 {
169174 var y = - VerticalOffset ;
175+ var thisRect = new Rect ( finalSize ) ;
176+ var visibleMaxWidth = 0.0 ;
170177
171178 foreach ( FrameworkElement child in Children )
172179 {
173180 var isFixed = GetIsFixed ( child ) ;
174181 var x = isFixed ? 0 : - HorizontalOffset ;
175- child . Arrange ( new Rect ( x , y , child . DesiredSize . Width , child . DesiredSize . Height ) ) ;
182+ var childRect = new Rect ( x , y , child . DesiredSize . Width , child . DesiredSize . Height ) ;
183+ child . Arrange ( childRect ) ;
176184 y += child . DesiredSize . Height ;
185+
186+ if ( childRect . IntersectsWith ( thisRect ) && childRect . Right > visibleMaxWidth )
187+ {
188+ visibleMaxWidth = childRect . Right ;
189+ }
177190 }
178191
179- UpdateScrollInfo ( new Size ( ExtentWidth , ExtentHeight ) , finalSize ) ;
192+ UpdateScrollInfo ( new Size ( visibleMaxWidth , ExtentHeight ) , new Size ( finalSize . Width , finalSize . Height ) ) ;
180193 return finalSize ;
181194 }
182195
183196 void UpdateScrollInfo ( Size extent , Size viewport )
184197 {
185198 ExtentWidth = extent . Width ;
186199 ExtentHeight = extent . Height ;
200+ ScrollOwner ? . InvalidateScrollInfo ( ) ;
187201 ViewportWidth = viewport . Width ;
188202 ViewportHeight = viewport . Height ;
189203 ScrollOwner ? . InvalidateScrollInfo ( ) ;
0 commit comments