Nihar Ranjan
Nihar Ranjan

Reputation: 73

ListView - Scrollbar height keeps changing as I scroll

I have a ListView which is explicitly populated (no binding) with ListViewItems. Most of the items need to Visible and others should remain collapsed. All the items are of the same height.

The problem is if I have 100 items and first 60 are visible and the bottom 40 are in collapsed state, the scroll bar's height become something based on the assumption that all the 100 items are in visible state and the scroll bar's height becomes less than what it should be. But when I scroll down to 60, it realizes that the rest 40 are in collapsed state and therefore increases the scroll bar's height to make it appropriate for 60 items in the list view.

I initially thought it may be because of virtualization. But I dod not have any binding of data to the list view. I also tried to set the height of the items to 0 that need to be in collapsed state which did not give me the desired result.

What I need is, if there are 60 items visible and 40 collapsed then the scroll bar's height should be based on only 60 items in the list view and should remain constant. Is it possible to achieve?

Upvotes: 4

Views: 2190

Answers (2)

Mike-Kilo
Mike-Kilo

Reputation: 1322

I had exactly the same problem, and the answer can be found here: Listbox scrollbar thumb changes size when content is variable height

Shortly, add ScrollViewer.CanContentScroll="False" on the ListBox and the scrollbar will have constant height regardless on the number of collapsed items.

By the way, I am aware that the question is almost 2 years old, however I'd like to leave it for future reference.

Upvotes: 6

Kent Boogaart
Kent Boogaart

Reputation: 178820

I'm not sure what made you decide it wasn't virtualization, as that is what it must be. Try turning off virtualization:

<ListView VirtualizingStackPanel.IsVirtualizing="False"  ...

Upvotes: 2

Related Questions