How to Check Listview Hit bottom with ObservableCollection Xamarin.Forms

SimonGhost 256 Reputation points

Hello Everyone, I searched a lot about how to make List view with (Load More) Feature but i have problem with check list view hit bottom or the last item of listview because i want to show 10 items in listview and check if listview hit the last item and load another 10 items...
so this my xaml.cs file:

ObservableCollection<WorldData> ADITM = new ObservableCollection<WorldData>();
public ObservableCollection<WorldData> ls1 { get { return ADITM; } }
public class WorldData
    public string Name { set; get; }
    public string Image { set; get; }

and i have problem in Listview ItemAppearing event:

 private void MyListview_ItemAppearing(object sender, ItemVisibilityEventArgs e)
            if (isLoading || ADITM.Count == 0)

            //when Listview hit bottom
            if (e.Item.ToString() == ADITM[ADITM.Count - 1])

output Error is:
Operator '==' cannot be applied to operands of type 'string' and 'MainWorlds.WorldData'

how to fix this Error and thanks :) and what the best way to show large data in listview ? is load all json data and show 10 items and when hit bottom show another 10 ? or limit json to get 10 items and request another 10 items and show it

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

Accepted answer
  1. JarvanZhang 23,951 Reputation points

    Hello SimonGhost-8216,​

    Welcome to our Microsoft Q&A platform!

    output Error is: Operator '==' cannot be applied to operands of type 'string' and 'MainWorlds.WorldData'

    This is because e.Item.ToString() returns a string value, but e.Item is type of the 'WorldData' in your project. In the ItemAppearing event, e.Item is the type of Model data. You could use it directly to detect it the bottom item is the last item. Or you can also use e.ItemIndex to check the index of the bottom item.

    Here is the sample code, you could refer to it.

       private void ListView_ItemAppearing(object sender, ItemVisibilityEventArgs e)  
           if (e.Item == ADITM[ADITM.Count - 1])  
           //or use e.ItemIndex to detect if it's the last item  
           //if (e.itemindex == aditm.count - 1)  
           //    loadmore();  

    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.

0 additional answers

Sort by: Most helpful