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

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

现在我这样做:

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

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

谢谢。

我想到了。 看来我应该从ScrollBar(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!"); } } 
 //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 } } } 

对于UWP,我得到了这样的

    private void scroll_ViewChanged(object sender, ScrollViewerViewChangedEventArgs e) { var scrollViewer = (ScrollViewer)sender; if (scrollViewer.VerticalOffset == scrollViewer.ScrollableHeight) btnNewUpdates.Visibility = Visibility.Visible; }