Xamarin Forms: How to detect the scrollview(or expander) end or top reached?

Sreejith Sree 1,251 Reputation points
2021-03-11T15:27:03.737+00:00

I need to load more data when scrollview reaches the end or top. I found the same thread over here, but on that, I didn't understand what is MyScrollView.

private void OnScrolled(object sender, ScrolledEventArgs e)
{
    MyScrollView scrollView = sender as MyScrollView;
    double scrollingSpace = scrollView.ContentSize.Height - scrollView.Height;

    if (scrollingSpace <= e.ScrollY)
    {
       //reached end
    }
}

I implemented the same in ListView using the ItemAppearing event. But currently, I am using Expander on the UI to display data. Is there any same kind of event for the expander to reach the end and beginning? The expander is inside of a scrollview, that's why I started researching about the scrollview end event.

Help me to find a way to trigger some kind of event when scrollview reaches end or beginning?

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,294 questions
0 comments No comments
{count} votes

Accepted answer
  1. Sreejith Sree 1,251 Reputation points
    2021-03-15T08:05:37.317+00:00

    Like I mentioned in the question I have implemented the same feature in ListView using the ItemAppearing event. But in this case, my data is a list of items inside another list. That's why I forced to use the Expander component to display the data on the UI.

    At the same time, I need to load more items when the Expander bottom reaches. But Expander doesn't provide the related event because it is not a scrollable control. So that I tried to find out an event for the ScrollView component. But no luck for that also.

    Finally, I decided to change the data to a single list from a list inside another list. I have converted that using some for loops and now the data is suitable for ListView. And I have implemented the load more feature using the ItemAppearing event.

    Thanks @JarvanZhang

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. JarvanZhang 23,951 Reputation points
    2021-03-12T02:59:04.657+00:00

    Hello,​

    Welcome to our Microsoft Q&A platform!

    Is there any same kind of event for the expander to reach the end and beginning?

    Expander doesn't provide the related event because it self is not a scrollable control.

    I found the same thread over here, but on that, I didn't understand what is MyScrollView.

    In you posted link, Bruno may use a custom ScrollView in his project. You could just change the 'MyScrollView' to ScrollView as below:

       private void ScrollView_Scrolled(object sender, ScrolledEventArgs e)  
       {  
           var scrollView = sender as ScrollView;  
           double scrollingSpace = scrollView.ContentSize.Height - scrollView.Height;  
         
           if (scrollingSpace > e.ScrollY)  
               return;  
         
           //do the work  
           //the scrollView has scrolled to the last item  
       }  
    

    Check this link: https://stackoverflow.com/a/57558768/11083277

    Best Regards,

    Jarvan Zhang


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.