Insert a Label in the empty groups of the CollectionView

Stefano M 91 Reputation points
2021-03-20T23:58:01.107+00:00

Inside a CollectionView I have various groups, some with elements, others empty in which there is no element inside, but only the name of the group. In empty groups is it possible to insert a Label instead of the object of my class?

public class Diary
{    
     public DateTime Dt { get; set;}                          
     public string Nota { get; set; }
}

DiaryGroup hgroup = new DiaryGroup(NameGroup), new ObservableCollection<Diary>());

public ObservableCollection<DiaryGroup> TotalDiary = new ObservableCollection<DiaryGroup>();
TotalDiary.Add(hgroup);
Developer technologies | .NET | Xamarin
0 comments No comments
{count} votes

Accepted answer
  1. JessieZhang-MSFT 7,716 Reputation points Microsoft External Staff
    2021-03-22T04:29:14.107+00:00

    Hello,

    Welcome to our Microsoft Q&A platform!

    You can add a GroupFooterTemplate for your CollectionView. You can refer to the official sample here .

    Please pay attention to VerticalListEmptyGroupsPage.xaml, the code snippet is :

            <CollectionView.GroupFooterTemplate>  
                <DataTemplate>  
                    <Label Text="{Binding Count, StringFormat='Total animals: {0:D}'}"  
                           Margin="0,0,0,10" />  
                </DataTemplate>  
            </CollectionView.GroupFooterTemplate>  
    

    When the first group is empty, the result is:
    79994-image.png

    Best Regards,

    Jessie Zhang

    ---
    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.