StackPanel in ScrollViewer : invalid visual descendant bounds after adding items (making vertical scrollbar appear) then removing items #9077
Labels
Investigate
Requires further investigation by the WPF team.
Description
StackPanel in ScrollViewer : when adding items to StackPanel (to make vertical scrollbar appear than removing them), than removing some of them (which makes scrollbar disppear), VisualTreeHelper.GetDescendantBounds() provides an incorrect value, which corresponds to the vertical scrollbar height before removing items.
=> Several possible side effects. In my case, an OpacityMask was stretched.
Note : VisualTreeHelper.GetContentBounds is correct though.
Reproduction Steps
I have a StackPanel in a scrollviewer.
I add items to this StackPanel so that vertical scrollbar appears, than I remove some them (to make scrollbar disappear).
I do it programmatically (stackPanel.Children.Add/Remove).
VisualTreeHelper.GetDescendantBounds then gives an incorrect height for my stackPanel, which corresponds to the scrollbar height before I remove some items.
If I spy the track control inside the scrollbar, its actual height is the invalid one.
Expected behavior
VisualTreeHelper.GetDescendantBounds() should provide the real height
Actual behavior
VisualTreeHelper.GetDescendantBounds() provide the bad height (see above).
Regression?
No response
Known Workarounds
My issue was related to OpacityMask => I've forced the mask ViewPort height from my ScrollViewer ActualHeight.
Impact
No response
Configuration
No response
Other information
No response
The text was updated successfully, but these errors were encountered: