嘿我怎样才能检测到我的ListView向上或向下滚动?
我有这个:
private void MainPage_OnLoaded(object sender, RoutedEventArgs e) { var scrollViewer = MyListView.GetFirstDescendantOfType(); scrollViewer.ViewChanged += BarScroll; } private void BarScroll(object sender, ScrollViewerViewChangedEventArgs e) { var scrollbars = (sender as ScrollViewer).GetDescendantsOfType ().ToList(); var verticalBar = scrollbars.FirstOrDefault(x => x.Orientation == Orientation.Vertical); if (verticalBar) (/*If ListView is scrolled up*/) { //Code when the ListView is scrolled up } else (/*If ListView is scrolled down*/) { //Code for when the ListView is scrolled down } }
我需要对"verticalBar.Height> verticalBar.ActualHeight"做些什么吗?
以这种方式修改BarScroll处理程序并将私有变量添加到主类以保持旧的scroll offset值:
private double offset; private void BarScroll(object sender, ScrollViewerViewChangedEventArgs e) { double newOffset = (sender as ScrollViewer).VerticalOffset; if ( newOffset > offset ) { //Logic for scroll down } else if ( newOffset < offset ) { //Logic for scroll up } offset = newOffset; }