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

编程入门 行业动态 更新时间:2024-10-23 18:32:26
本文介绍了如何检测 ListView 向上或向下滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

有没有办法检测ListViewScrollViwer 处于滚动模式并停止滚动.在 windows phone 8.1 ListView 中,我们无法获得滚动查看器的引用.

Is there a way to detect that ScrollViwer of ListView is in scrolling mode and stopped scrolling. In windows phone 8.1 ListView we can not get reference of the scrollviewer.

有人在 Windows Phone 8.1 WinRT 应用程序中做过吗?

Any one done it in windows phone 8.1 WinRT app?

推荐答案

一旦 ListView Loaded 你可以像这样得到 ScrollViewer :

Once the ListView is Loaded you can get the ScrollViewer like this:

var sv = (ScrollViewer)VisualTreeHelper.GetChild(VisualTreeHelper.GetChild(this.ListV, 0), 0);

编辑

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

As Romasz suggested, once you get the ScrollViewer, you can use its ViewChanged event, to monitor when it is scrolling and when it stops.

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

Also, here's the generic extension method that I use for traversing the visual tree:

// 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,请执行以下操作:

To get the ScrollViewer using this methos, do this:

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

这篇关于如何检测 ListView 向上或向下滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-25 13:31:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1117717.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:ListView

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!