ListView OnItemAppearing Behavior

RaymondKellyRaymondKelly USMember ✭✭✭
edited April 2016 in Xamarin.Forms

I am having a hard time understanding OnItemAppearing. I see two behaviors that seem unexpected to me.

  1. OnAppearing fires for every item added to the list regardless if it really appears or not. So for instance if I bulk add 1000 items to an bound ObservableCollection, I get 1000 OnItemAppearing events fired even though only 10 are visible in the List. This makes it difficult to lazy load things such as images. Any insight on how to handle this?

  2. Calling ListView.ScrollTo fires OnItemAppearing for every item in the list. I am trying to programmatically scroll to the bottom. with this code:

private void OnItemAppearing(object sender, ItemVisibilityEventArgs e) { _listViewChat.ScrollTo(chatMessages.Last(), ScrollToPosition.End, false); }

When ScrollTo is called, OnItemAppearing fires again for every item in the ListView which again calls ScrollTo. Its almost like its going through every item in the list to scroll to the bottom. So it eventually chews itself up and blows up. This is occurring on Android. UWP does not have this behavior, and havent tested iOS yet. I cannot seem to find a good Scroll To Bottom solution. Ideas?

Thanks

Answers

  • RaymondKellyRaymondKelly USMember ✭✭✭

    I should add that on iOS, ScrollTo seems to start from the top and go to the bottom and you can see the ListView scroll with each call. Am I the only one seeing this??

Sign In or Register to comment.