Articles in this section
Category / Section

How to update empty group header text in Xamarin.Forms ListView (SfListView )?

1 min read

You can change the GroupHeader text based on the items count in Xamarin.Forms ListView. Please refer to the following documentation to load an empty group using ListView.

XAML

Define the converter that is bound to the GroupHeader with GroupResult as binding to display GroupHeader text based on the items count. 


<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:ListViewXamarin"
             xmlns:syncfusion="clr-namespace:Syncfusion.ListView.XForms;assembly=Syncfusion.SfListView.XForms"
             x:Class="ListViewXamarin.MainPage">
    ...
    <ContentPage.Resources>
        <ResourceDictionary>
            <local:GroupHeaderConverter x:Key="GroupHeaderConverter"/>
        </ResourceDictionary>
    </ContentPage.Resources>
  <ContentPage.Content>
        <StackLayout>
            <syncfusion:SfListView x:Name="listView" ItemSize="60" ItemsSource="{Binding ContactsInfo}">
                <syncfusion:SfListView.ItemTemplate >
                    <DataTemplate>
                        ...
                    </DataTemplate>
                </syncfusion:SfListView.ItemTemplate>
                <syncfusion:SfListView.GroupHeaderTemplate>
                    <DataTemplate>
                        <Grid BackgroundColor="Teal">
                            <Label Text="{Binding ., Converter={StaticResource GroupHeaderConverter}}" FontSize="22" TextColor="White" FontAttributes="Bold" VerticalOptions="Center" Margin="10,0,0,0" />
                            <Grid Grid.Column="1" HorizontalOptions="End" VerticalOptions="End">
                                <Image x:Name="button" Source="Add.png" HeightRequest="50" WidthRequest="40" >
                                    <Image.GestureRecognizers>
                                        <TapGestureRecognizer Command="{Binding Path=BindingContext.ButtonTappedCommand, Source={x:Reference listView}}" CommandParameter="{Binding .}"/>
                                    </Image.GestureRecognizers>
                                </Image>
                            </Grid>
                        </Grid>
                    </DataTemplate>
                </syncfusion:SfListView.GroupHeaderTemplate>
            </syncfusion:SfListView>
        </StackLayout>
    </ContentPage.Content>
</ContentPage>

C#

Returns the text based on the GroupResult.Count property. 

public class GroupHeaderConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if (value == null) return null;
 
        var groupResult = value as GroupResult;
        if (groupResult.Key.ToString() == "WORK")
            return groupResult.Count > 1 ? "WORK" : "EMPTY WORK";
        else
            return groupResult.Count > 1 ? "PERSONAL" : "EMPTY PERSONAL";
    }
 
    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

View sample in GitHub

Demo image to change the GroupHeader text based on its count in Xamarin.Forms SfListView

Conclusion

Hope you enjoyed learning about how to add a seperator between items in a Xamarin.Forms Listview.

You can refer to our Xamarin.Forms ListView feature tour page to learn about its other groundbreaking feature representations. You can explore our  Xamarin.Forms documentation to understand how to present and manipulate data.

For current customers, you can check out our Angular 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 Angular Diagram and other Angular components.

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 (0)
Please  to leave a comment
Access denied
Access denied