Articles in this section
Category / Section

How to display the items count of group in the group header item in Xamarin.Forms ListView?

1 min read

In Xamarin.Forms ListView, you can display the items count for each group in the group header item by customizing the GroupHeaderTemplate property and to expand/collapse the groups at runtime you need to define the AllowGroupExpandCollapse as true like following code example. So, when you tap on the group header, then the tapped group gets collapse if the group is in expand state and vice-versa.

XAML

<listView:SfListView x:Name="listView" ItemSize="70"
                     GroupHeaderSize="60"  AllowGroupExpandCollapse="True"
                     ItemsSource="{Binding Items}"/>

 

To display the total number of items in each group in the group header item, you need to bind the Count property in the GroupHeaderTemplate as like following code example.

XAML

<listView:SfListView.GroupHeaderTemplate>
  <DataTemplate>
    <Grid BackgroundColor="#E4E4E4">
      <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*"/>
        <ColumnDefinition Width="*"/>
      </Grid.ColumnDefinitions>
      <StackLayout Orientation="Horizontal" HorizontalOptions="Start"
                   VerticalOptions="Center" Padding="10,0,0,0">
        <Label Text="{Binding Key}" TextColor="Black" FontSize="Medium"/>
        <Label Text="Year" TextColor="Black" FontSize="Medium"/>
      </StackLayout>
      <StackLayout Orientation="Horizontal" Grid.Column="1" Padding="0,0,20,0"
                   HorizontalOptions="EndAndExpand" VerticalOptions="Center">
        <Label Text="{Binding Count}" TextColor="Black" FontSize="Medium"/>
        <Label Text="Item(s)" TextColor="Black" FontSize="Medium"/>
      </StackLayout>
    </Grid>
  </DataTemplate>
</listView:SfListView.GroupHeaderTemplate>

 

Now run the application to render the following output.

C:\Users\dinesh.babuyadav\AppData\Local\Microsoft\Windows\INetCache\Content.Word\Screenshot_20171003-130923.png

 

Sample Link: ListView_Grouping


Conclusion

I hope you enjoyed learning about how to display the items count of group in the group header item in  Xamarin.Forms ListView.

You can refer to our Xamarin.Forms ListView feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments
Please  to leave a comment
Access denied
Access denied