Why do we need to create a Custom ViewCell?

Technology CommunityCategory: XamarinWhy do we need to create a Custom ViewCell?
VietMX Staff asked 3 years ago

Built in cell actually allows us to show some data into the List for some simple scenarios. But, in some real world scenarios, these simple cells can’t fulfill all our needs. For example, let’s say we want to show few labels, 2 buttons, and one image to the right side of the cell. This scenario can’t be accomplished using built-in cells. So, we have to go for some customization. In the ListView‘s DataTemplate, we can simply wrap our own set of controls in ViewCell Tag.

Consider:

<ListView RowHeight="60">
    <ListView.ItemTemplate>
        <DataTemplate>
            <ViewCell>
                <StackLayout Orientation="Horizontal" HorizontalOptions="Fill">
                    <StackLayout Orientation="Vertical">
                        <Label Text = "{Binding Name}" />
                        <Label Text = "{Binding Email}" />
                    </StackLayout>
                    <Image Source="{Binding ProfileImage}" HorizontalOptions="End" />
                    <Button Text="Delete" WidthRequest="100" HeightRequest="50" />
                </StackLayout>
            </ViewCell>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>