加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

xaml – 如何检测ListView向上或向下滚动

发布时间:2020-12-14 01:47:36 所属栏目:Windows 来源:网络整理
导读:有没有办法检测ListView的ScrollViwer处于滚动模式并停止滚动.在 Windows Phone 8.1 ListView中我们无法获得scrollviewer的参考. 任何人在Windows Phone 8.1 WinRT应用程序中完成它? 加载ListView后,您可以像这样获取ScrollViewer: var sv = (ScrollViewer
有没有办法检测ListView的ScrollViwer处于滚动模式并停止滚动.在 Windows Phone 8.1 ListView中我们无法获得scrollviewer的参考.

任何人在Windows Phone 8.1 WinRT应用程序中完成它?

加载ListView后,您可以像这样获取ScrollViewer:
var sv = (ScrollViewer)VisualTreeHelper.GetChild(VisualTreeHelper.GetChild(this.ListV,0),0);

编辑

正如Romasz建议的那样,一旦你获得了ScrollViewer,就可以使用它的ViewChanged事件来监视它何时滚动以及何时停止.

此外,这是我用于遍历可视树的通用扩展方法:

// The method traverses the visual tree lazily,layer by layer
// and returns the objects of the desired type
public static IEnumerable<T> GetChildrenOfType<T>(this DependencyObject start) where T : class 
{
    var queue = new Queue<DependencyObject>();
    queue.Enqueue(start);

    while (queue.Count > 0) {
        var item = queue.Dequeue();

        var realItem = item as T;
        if (realItem != null) {
             yield return realItem;
        }

        int count = VisualTreeHelper.GetChildrenCount(item);
        for (int i = 0; i < count; i++) {
            queue.Enqueue(VisualTreeHelper.GetChild(item,i));
        }
    }
}

要使用此方法获取ScrollViewer,请执行以下操作:

var sv = yourListView.GetChildrenOfType<ScrollViewer>().First();

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读