检测 WPF 列表视图滚动条何时位于底部? [英] Detect when WPF listview scrollbar is at the bottom?

查看:26
本文介绍了检测 WPF 列表视图滚动条何时位于底部?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法检测ListViewScrollViewer的滚动条是否到达了虚拟滚动空间的底部?我想检测这个以从服务器获取更多项目以放入 ListView 上的绑定 ObservableCollection.

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).

谢谢.

推荐答案

我想通了.似乎我应该从 ScrollBar(<ListView ScrollBar.Scroll="currentTagNotContactsList_Scroll" in 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屋!

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