Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 89864

Hiding Collection View Group Header

$
0
0

Is there any way we can hide CollectionView's group header if the group is empty when grouping is enabled?

Let's take the example from the official docs:

    // Extended List
    public class AnimalGroup : List<Animal>
    {
        public string Name { get; private set; }

        public AnimalGroup(string name, List<Animal> animals) : base(animals)
        {
            Name = name;
        }
    }

    // Viewmodel property
    public List<AnimalGroup> Animals { get; private set; } = new List<AnimalGroup>();

     // View
        <CollectionView ItemsSource="{Binding Animals}" IsGrouped="true">
            <CollectionView.GroupHeaderTemplate>
                <DataTemplate>
                    <Label Text="{Binding Name}"
                           BackgroundColor="LightGray"
                           FontSize="Large"
                           FontAttributes="Bold" />
                </DataTemplate>
            </CollectionView.GroupHeaderTemplate>
            <CollectionView.ItemTemplate>
                <DataTemplate>
                ...............
            </DataTemplate>
            </CollectionView.ItemTemplate>
        </CollectionView>

Is it possible to hide the group header if the items of that header are empty?


Viewing all articles
Browse latest Browse all 89864


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>