Forum Xamarin Xamarin.Forms

Does ListViewCachingStrategy.RetainElement behave as expected on UWP?

JohnHardmanJohnHardman GBUniversity admin

The documentation for ListViewCachingStrategy.RetainElement at says:

"Indicates that for every item in the List View's ItemsView<TVisual>.ItemsSource property, a single unique element will be constructed from the DataTemplate."

That's what I see on Android and iOS, but on UWP I am seeing constructors being called more than once for the same element in ItemsSource. For example, if I scroll down to the bottom of a list and then back up to the top again, I see new instances being constructed for the cells at the top of the list. I am using a DataTemplateSelector and multiple DataTemplates, but wouldn't expect this to cause any complications. Using RetainElement, I would expect everything to be nice and simple if there is enough memory to hold all the elements, and would expect an out-of-memory if there isn't enough memory. Am I missing something? Is anybody else seeing issues with RetainElement on UWP?

(Needless to say, I'm not actually intending to use RetainElement, but switched to using it whilst debugging another issue as I though RetainElement would remove some of the complexity - which it seems to on Android and iOS, but not on UWP).

Best Answer


  • JohnHardmanJohnHardman GBUniversity admin

    Repro sample now added.

  • Rameshbodh_Rameshbodh_ Member ✭✭

    with listview caching strategy to retain element for android listview is not as expected if we try to refresh list

Sign In or Register to comment.