嘿我怎样才能检测到我的ListView向上或向下滚动?
我有这个:
private void MainPage_OnLoaded(object sender, RoutedEventArgs e)
{
var scrollViewer = MyListView.GetFirstDescendantOfType<ScrollViewer>();
scrollViewer.ViewChanged += BarScroll;
}
private void BarScroll(object sender, ScrollViewerViewChangedEventArgs e)
{
var scrollbars = (sender as ScrollViewer).GetDescendantsOfType<ScrollBar>().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
}
}
我是否需要对&#34; verticalBar.Height&gt;执行某些操作? verticalBar.ActualHeight&#34;
答案 0 :(得分:6)
以这种方式修改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;
}