获取ListView控件可见的项目 [英] Get ListView Visible items

查看:166
本文介绍了获取ListView控件可见的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个的ListView 可能包含了很多的项目,所以它是虚拟化和循环利用项目。它不使用排序。我需要更新一些值显示,但是当有太多的项目,实在是太慢了,更新的一切,所以我想只刷新可见项目。

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.

我怎么能得到当前显示的所有项目的列表?我试图寻找到的ListView 的ScrollViewer ,但我仍然不知道如何来实现这一目标。该解决方案必须不经过的所有项目,以测试是否可以看到的,因为这将是太慢了。

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.

我不知道code或XAML是有用的,它只是一个虚拟化 / 回收的ListView 及其 ItemSource 绑定到一个阵列

I'm not sure code or xaml would be useful, it is just a Virtualized/Recycling ListView with its ItemSource bound to an Array.

编辑: 答:
感谢akjoshi,我找到了办法:

Edit : Answer :
thanks to akjos I found the way :

  • 获得的ScrollViewer 的ListView (以 FindDescendant 方法,你可以做你自己的 VisualTreeHelper )。

  • get the ScrollViewer of the ListView (with a FindDescendant method, that you can do yourself with the VisualTreeHelper ).

读取其 ScrollViewer.VerticalOffset :这是显示的第一个项目的数量

read its ScrollViewer.VerticalOffset : it is the number of the first item shown

推荐答案

有一个看MSDN在这个问题上表现出的技术,找出可见的ListView 项目 -

Have a look at this question on MSDN showing a technique to find out the visible ListView items -

如何找到行( ListViewItem的(S))在ListView,实际上是可见的?

您应该做的另一件事是使用 的ObservableCollection 为你的 ItemSource 而不是一个阵列;这肯定会提高性能

Another thing you should do is to use ObservableCollection as your ItemSource instead of an Array; that will definitely improve the performance.

更新:

雅那可能是真实的(阵列的ObservableCollection ),但我想看到一些相关的统计数据本;

Ya that might be true(array vs. ObservableCollection) but I would like to see some statistics related to this;

的ObservableCollection 的真正的好处是,如果你有一个条件,添加/从你的的ListView 在运行删除项目 - 时间,在发生阵列,你将不得不重新分配 ItemSource 中的ListView 的ListView 第一扔掉了previous项目,并重新生成整个列表。

The real benefit of ObservableCollection is if you have a requirement to add/remove items from your ListView at run-time, in case of an Array you will have to reassign the ItemSource of ListView and the ListView first throws away its previous items and regenerates its entire list.

这篇关于获取ListView控件可见的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆