question

StefanoM-9408 avatar image
0 Votes"
StefanoM-9408 asked JessieZhang-2116 answered

Insert a Label in the empty groups of the CollectionView

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);
dotnet-xamarin
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

JessieZhang-2116 avatar image
1 Vote"
JessieZhang-2116 answered

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.



image.png (62.4 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.