当检测列表视图WPF滚动条是底部? [英] Detect when WPF listview scrollbar is at the bottom?
问题描述
有没有一种方法来检测,如果从的ScrollViewer
在的ListView
已经达到了底部的滚动条虚拟滚动空间?我想检测到这种从服务器获取更多的项目投入绑定的ObservableCollection
在的ListView
。
Is there a way to detect if the scrollbar from the ScrollViewer
in a ListView
has reached the bottom of the virtual scroll space? I would like to detect this to fetch more items from the server to put into the bound ObservableCollection
on the ListView
.
现在我这样做:
private void currentTagNotContactsList_scrollChanged(object sender, ScrollChangedEventArgs e) {
ListView v = (ListView)sender;
if (e.VerticalOffset + e.ViewportHeight == e.ExtentHeight) {
Debug.Print("At the bottom of the list!");
}
}
这甚至正确吗?我还需要垂直滚动条来区分导致事件和水平滚动条导致它(即我不想让生成调用服务器,如果你在盒子的底部水平滚动)。
Is this even correct? I also need to differentiate between the vertical scrollbar causing the event and the horizontal scrollbar causing it (i.e. I don't want to keep generating calls to the server if you scroll horizontally at the bottom of the box).
感谢。
推荐答案
我想通了。看来我应该已经从滚动条(< ListView控件ScrollBar.Scroll =currentTagNotContactsList_Scroll
在XAML)获取事件本身,而不是浏览器。这工作,但我只是要搞清楚一个方式,以避免事件处理程序被反复调用一次的滚动条了。也许一个定时器将是很好的:
I figured it out. It seems I should have been getting events from the ScrollBar (<ListView ScrollBar.Scroll="currentTagNotContactsList_Scroll"
in XAML) itself, rather than the viewer. This works, but I just have to figure a way to avoid the event handler being called repeatedly once the scrollbar is down. Maybe a timer would be good:
private void currentTagNotContactsList_Scroll(object sender, ScrollEventArgs e) {
ScrollBar sb = e.OriginalSource as ScrollBar;
if (sb.Orientation == Orientation.Horizontal)
return;
if (sb.Value == sb.Maximum) {
Debug.Print("At the bottom of the list!");
}
}
这篇关于当检测列表视图WPF滚动条是底部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!