ListView and ViewCell reuse ... or not?

FonagerFonager DKMember ✭✭
edited November 3 in Xamarin.Forms


I have a fairly simple Xamarin Forms (2.4.0) project and only focusing on the Android part for now. I use the MasterDetailPage as main navigation pattern. Each selected page, is wrapped in a NavigationPage object, as everyone also suggests.

But I dont quite understand the way it is working. The default page is a page "TicketPage" and this consists of a ListView :

        var list = new ListView(ListViewCachingStrategy.RecycleElement)
            ItemTemplate = new DataTemplate(typeof(TicketView)),
        list.SetBinding(ListView.ItemsSourceProperty, "FareItemsList");

Nothing special there. And when the page is first instantiated, it of cause makes a call to the TicketView constructer for each composed cell, as I would expect.

But when I navigate away from this page and the .Detail of the MasterDetailPage is changed to a new NavigationPage, what happens with the "old" page, which is not visible anymore? Is something released or ? My menu class is still keeping a reference to both the NavigationPage and the TicketPage objects. Because when I go back and click the "ticket" menu and the NavigationPage and TicketPage is reused, something strange happens when the page should be shown again: the constructor is not called, as expected, but the cells are recreated again (10 cells). Is that expected behaviour? I kinda understand that, but the process is painfully slow and results in very bad stuttering in the animation of the menu (Drawer) disappearance.

If i time the constructor for each cell, it takes 3-4 ms, so it cannot be this process taking up all the time, as I currently only have 10 cells in the list?

How does forms "reuse" existing pages? And should it really be that slow?

Hope for some enlightening answers :-)

Kent Fonager

Sign In or Register to comment.