question

JohnHair avatar image
0 Votes"
JohnHair asked ColeXia-MSFT edited

CollectionView performance

I have a new list requirement and decided to try the CollectionView, the newer alternative to the ListView that Xamarin appears to be recommending for performance and virtualisation advantages.

Using XF 5.0.0.1931 on iOS, the performance appears to be dreadful. I have a DataTemplateSelector, but the templates need to build parts of the layout in each row based on the data from the model. I do this by overriding OnBindingContextChanged, clearing the changeable content and rebuilding as required. The initial load of the visible rows is fine, but shortly after scrolling I can see binding contexts changing for visible rows before flicking back, which triggers a lot of on screen flickering and jumping.

Anyone else using CollectionView successfully? Is there a better way of creating dynamic content in a 'cell'? No, I cannot have data templates that cover all these scenarios.

dotnet-xamarin
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

JohnHair avatar image
0 Votes"
JohnHair answered

@ColeXia-MSFT yeah I came to the same conclusion, CollectionView isn't fit for purpose. Thank you for confirming that.
I would suggest you put a label on the control as such to warn other developers from using it, and then remove it from the code base.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

ColeXia-MSFT avatar image
0 Votes"
ColeXia-MSFT answered ColeXia-MSFT edited

Hello,

Welcome to Microsoft Q&A!

CollectionView and ListView are designed for sharing the same DataTemplate (sometimes we need to use DataTemplateSelector).

Actually virtualisation marks collectionView reuse the row/cell and it should not recreate the controls .

Recreating controls while scrolling will lead to bad performance , I suggest you use a ScrollView to add all kinds of the subviews, in this scenario the subview is created only once , the flickering and jumping would not occur while scrolling .

Best Regards,
Cole Xia


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.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.