检测WPF列表视图滚动条何时位于底部?

Max*_*Max 11 c# wpf listview scroll

有没有办法检测来自ScrollViewera中的滚动条ListView是否已到达虚拟滚动空间的底部?我想检测这从服务器获取更多的项目投入到绑定ObservableCollectionListView.

现在我这样做:

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!");
    }

}
Run Code Online (Sandbox Code Playgroud)

这甚至是正确的吗?我还需要区分导致事件的垂直滚动条和导致它的水平滚动条(即如果你在框的底部水平滚动,我不想继续生成对服务器的调用).

谢谢.

Max*_*Max 9

我想到了.看来我应该从ScrollBar(<ListView ScrollBar.Scroll="currentTagNotContactsList_Scroll"在XAML中)获取事件,而不是查看器.这是有效的,但我只需要想办法避免在滚动条停止后重复调用事件处理程序.也许计时器会很好:

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!");

    }

}
Run Code Online (Sandbox Code Playgroud)

  • Windows 10中的ListView不存在ScrollBar.Scroll ..如何在Windows 10中实现此要求 (3认同)

Nar*_*yal 5

//A small change in the "Max's" answer to stop the repeatedly call.
//this line to stop the repeatedly call
ScrollViewer.CanContentScroll="False"

private void dtGrid_ScrollChanged(object sender, ScrollChangedEventArgs e)
                {
//this is for vertical check & will avoid the call at the load time (first time)
                    if (e.VerticalChange > 0)
                    {
                        if (e.VerticalOffset + e.ViewportHeight == e.ExtentHeight)
                        {
                            // Do your Stuff
                        }
                    }
                }
Run Code Online (Sandbox Code Playgroud)