I am using Xamarin.Forms v4.8.0.1534 and I have a list of items being displayed by a CollectionView
. I have new items coming in at random intervals and the user may have scrolled the list to look at any historical item. The list needs to operate in two modes:
If the list is showing the last item added when a new item is added (Monitoring mode), then the list should scroll to show the new item in full. if the user has scrolled the list to look at historical items then the list should not move when new items are added.
It is an option to add new items to the top of the list or the bottom.
If the option is set to add items to the top of the list and the ItemsUpdatingScrollMode = KeepScrollOffset
then everything works as required.
However, there does not seem to be an equivalent setting for adding items at the bottom of the list.
I have tried different settings for ItemsUpdatingScrollMode
, but nothing works as required, and I have also looked for ways to check if the last item added is visible in the CollectionView
before adding the new one. The idea then would be to use ScrollTo
if relevant, but I cannot find any way to check CollectionView
item visibility.
I'm not sure If I am missing something obvious but any help would be appreciated especially around ways to check CollectionView
item visibility.
However, there does not seem to be an equivalent setting for adding items at the bottom of the list.
KeepScrollOffset
maintains the scroll offset relative to the beginning of the list. If you added the items at the bottom, the offset won't be changed. Therefore, the collection view won't scroll to the item and will keep the original position.
If you want it to scroll to the bottom side when new items added, try the KeepLastItemInView
mode. And ScrollTo
helps scroll to any item if needed.
If you want to get the visible items in the collection view, we need to consume the customer renderer to access them on each platform. Refer to my another thread here:
https://forums.xamarin.com/discussion/175857/detect-collectionview-row-item-is-appeared
Hope it could give you some hints.
Answers
KeepScrollOffset
maintains the scroll offset relative to the beginning of the list. If you added the items at the bottom, the offset won't be changed. Therefore, the collection view won't scroll to the item and will keep the original position.If you want it to scroll to the bottom side when new items added, try the
KeepLastItemInView
mode. AndScrollTo
helps scroll to any item if needed.If you want to get the visible items in the collection view, we need to consume the customer renderer to access them on each platform. Refer to my another thread here:
https://forums.xamarin.com/discussion/175857/detect-collectionview-row-item-is-appeared
Hope it could give you some hints.
Thanks for the reply @LandLu, Ideally I would like a KeepScrollBottomOffset option but in the absence of that I will have to look into the custom renderer direction.
Firstly, I need to go back to the business unit and see if the functionality is worth the extra effort or if they would be happy to just have the items appear at the top.
Thanks again