How to detect ListView is scrolling up or down

后端 未结 3 886
耶瑟儿~
耶瑟儿~ 2020-12-10 07:18

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

3条回答
  •  清歌不尽
    2020-12-10 07:57

    You can find the ScrollViewer of your ListView by using VisualTreeHelper. For example like this:

    // method to pull out a ScrollViewer
    public static ScrollViewer GetScrollViewer(DependencyObject depObj)
    {
        if (depObj is ScrollViewer) return depObj as ScrollViewer;
    
        for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)
        {
            var child = VisualTreeHelper.GetChild(depObj, i);
    
            var result = GetScrollViewer(child);
            if (result != null) return result;
        }
        return null;
    }
    

    Once you have a ScrollViewer you can subscribe to its events:

    GetScrollViewer(yourListView).ViewChanged += yourEvent_ViewChanged;
    

提交回复
热议问题