0

I have a InfiniteListView which extend ListView from Xamarin Forms. I know when you on the last item in the list but how can i figure out if the user scrolled to the top of the list ?

Lennie
  • 2,199
  • 2
  • 15
  • 13

1 Answers1

1

Unfortunately, the Xamarin Forms ListView does not expose a Scrolled event or Position property. So your only option is to use the ItemAppearing and ItemDisappearing events.

When you subscribe to these events, you can figure out if the first cell is appearing again, after it disappeared first. This does not actually give you a 100% correct outcome, since it can happen that only a part of the first cell is shown.

If you want a perfect check that you are at the absolute top, you will have to resort to a custom renderer:

  • On iOS you can make use of the tableView.contentOffset.y property on the UITableView.

  • On Android it's a little bit more involved, as there are multiple (but no straightforward) ways to achieve this. See this answer for one possibility. This approach is originally meant for saving and restoring scroll position, so adjust it to your needs.

  • Other platforms have similar ideas. Check which native control the Xamarin Forms renderer creates, and then search the internet for possible solutions for that specific platform.

Community
  • 1
  • 1
Tim Klingeleers
  • 2,017
  • 9
  • 18