Forum Xamarin.Forms

Performant CollectionView datatemplates in Xamarin forms

philipzhengphilipzheng Member ✭✭
                        <CollectionView ItemsSource="{Binding Products}">
                                    <datatemplates:ProductSummaryTemplate />

When I try to put a ContentView inside of a CollectionView datatemplate, it seems to be rather slow compared to putting a ViewCell inside a ListView. I was wondering what is the recommended way to put a template inside a CollectionView? It seems like CollectionView does not allow you to put a ViewCell inside of it, but I read that ViewCell more performant than ContentView. My datatemplate looks like the below:

<ContentView ...>
    <Grid Padding="10">
            <RowDefinition Height="25" />
            <RowDefinition Height="25" />
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="Auto" />
            Source="{Binding thumbnail}" />
            Text="{Binding title}" />
            Text="{Binding description}"
            VerticalOptions="End" />

Best Answer


  • igorkr_10igorkr_10 Member ✭✭✭✭
    edited May 4

    Why do you need ContentView? You can remove it and leave just Grid
    But I don't think that it will change something

  • igorkr_10igorkr_10 Member ✭✭✭✭
    edited May 4

    I have tested the ListView and CollectionView in my application.

    ListView video
    CollectionView video



    For me ListView is more performant

  • philipzhengphilipzheng Member ✭✭

    Thank you @jezh for directing me to that documentation. It's useful to know that we can change the image caching to cache for longer than the default 1 day (see Also thank you to @igorkr_10 for helping me see that, at least sometimes, ListView is more performant. I had experienced that as well in my own testing but wasn't sure if that was just an anomaly.
    I still need to wrap the datatemplate in a ContentView because it seems that I can't have a datatemplate with just a grid in its own file unless it's wrapped with a contentview.

Sign In or Register to comment.