Why is the "ItemAppearing" event called for all ListView items when there are only a few visible?

PrullebakPrullebak NLMember ✭✭

Hello!

I got a grouped ListView with two groups and four item templates. They all have a few bindings. When loading the ListView it takes some time to render the rows, about 5 seconds... for 25 rows. In each row at the ViewModel i do a few calculations, for example calculating the week number of a specific DateTime and formate some lists. These calculations are heavy for all rows together.

Then i came across the "ItemAppearing" event. But this event is called for all rows, also for the rows that are not visible. I'm searching for a way to do heavy row tasks only when the row becomes visible, for example when the user swipes through the list.

Why is "ItemAppearing" called for all ListView items? Is this normal behaviour?

Answers

  • JonathenScaletJonathenScalet USMember ✭✭

    I'm having the same problem, trying to work around it.

    Have you come up with a solution?

  • clopezclopez ESMember ✭✭✭

    I don't know. I used ItemAppearing and it only triggers when the item associated appears on screen.
    Well, I had a problem with it but I can't remeber the solution: I had a list of items, and I put a view at the end, to add more items to it when it shows on screen, but as soon I load the page, the ItemAppearing triggers about three or four times.
    The problem was that the render didn't set the size of the rows until it finished to initialize, so for the first "frame", the size of the list item was zero, and then it triggers the ItemAppearing event.

    I have this on the xaml, in the item view definition:

    ItemAppearing="MyItemAppearing"

    And then, this is the MyItemAppearing method:

    async void MyItemAppearing(object sender, ItemVisibilityEventArgs e)
    {
    if (!ViewModel.IsInitialized)
    return;

            if (ViewModel.itemList.Last() == (MyItem)e.Item)
            {
                IsBusy = true;
    
                await AddMoreItemsToList();
    
                IsBusy = false;
            }
        }
    

    I hope it could help you finding the problem.

  • Mob_Dev_EnggMob_Dev_Engg USMember ✭✭

    it is not working on Ipad ios11 in xamarin

Sign In or Register to comment.