当前位置:  开发笔记 > 编程语言 > 正文

检测ListView何时"向上"或"向下"滚动?Windows Phone 8.1 ListView

如何解决《检测ListView何时"向上"或"向下"滚动?WindowsPhone8.1ListView》经验,为你挑选了1个好方法。

嘿我怎样才能检测到我的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"做些什么吗?



1> 小智..:

以这种方式修改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;
    }

推荐阅读
放ch养奶牛
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有