Get ListView Visible items
- by Vincent Piel
I have a ListView which might contains a lot of items, so it is virtualized and recycling items. It does not use sort. I need to refresh some value display, but when there are too many items, it is too slow to update everything, so I would like to refresh only the visible items.
How could I get a list of all currently displayed items ? I tried to look into the ListView or in the ScrollViewer, but I still have no idea how to achieve this. The solution must NOT go through all items to test if they can be seen, because this would be too slow.
I'm not sure code or xaml would be usefull, it is just a Virtualized/Recycling ListView with its ItemSource bound to an Array.
Edit Answer :
thanks to akjoshi, i found the way : get the ScrollViewer of the ListView (with a FindDescendant method, that you can do yourself with the VisualTreeHelper ).
Then use its ScrollViewer.VerticalOffset : it is the number of the first item shown and ScrollViewer.ViewportHeight : it is the count of items shown.
Rq : CanContentScroll must be true.