Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect when a ScrollViewer finishes scrolling?

BTW I'm using UWP in case it matters. So I am using a ListView and all ListViews have a ScrollViewer attached to them (in default template) by default. The problem is that I cannot find an event (on the ListView itself or on its ScrollViewer) that triggers when the ListView finishes scrolling.

I used the scrollViewer.ChangeView() method to automatically scroll to the beginning of the ListView and it uses an animation to scroll to the top, so I think that has something to do with it because the ViewChanged event fires before the animation completes. If I am correct about that then there would have to be a way to determine if the animation is complete because I need to be alerted when the ListView is completely idle again, which is only when the scroll animation completes. Thanks.

like image 987
LeBrown Jones Avatar asked Oct 25 '25 17:10

LeBrown Jones


1 Answers

You can wire up the scrollViewer's ViewChanged event, and check the IsIntermediate of the event argument.

private void ScrollViewer_ViewChanged(object sender, ScrollViewerViewChangedEventArgs e)
{
    if (e.IsIntermediate)
    {
        System.Diagnostics.Debug.WriteLine("scroll ongoing");
    }
    else
    {
        System.Diagnostics.Debug.WriteLine("scroll finish");
    }
}

This event is fired multiple times. When the scroll finishes, IsIntermediate is false.

like image 76
kennyzx Avatar answered Oct 28 '25 08:10

kennyzx