Get ListView Visible items

Posted by Vincent Piel on Stack Overflow See other posts from Stack Overflow or by Vincent Piel
Published on 2012-06-25T10:16:48Z Indexed on 2012/12/14 23:04 UTC
Read the original article Hit count: 671

Filed under:
|
|
|
|

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.

© Stack Overflow or respective owner

Related posts about c#

Related posts about wpf