Rohan
Rohan

Reputation: 11

Detect when Xamarin Scrollview has reached the end

I am using xamarin forms to display a list of items in a scrollview. I would like to add a feature so that when the user scrolls to the bottom of the page I can trigger an event (ex. load more items). Currently, I am using this OnScrolled Function to trigger the loading event:

private void OnScrolled()
        {
            if (Scroller.ScrollY >= (Scroller.ContentSize.Height -Scroller.Height)+1)
            {
               //load more items

            }
        }

The problem is that this function gets called multiple times even though the page has only been scrolled to the bottom once. Any tips on how to deal with this?

Upvotes: 1

Views: 3848

Answers (2)

SnailB
SnailB

Reputation: 1

Your method, it should not be used. There are a few things that might be helpful:

Upvotes: 0

Bruno Caceiro
Bruno Caceiro

Reputation: 7189

The method will be called multiple times, because your are using an event handler for the scroll changed.

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

            if (scrollingSpace <= e.ScrollY) // Touched bottom
                // Do the things you want to do
        }

Upvotes: 6

Related Questions