sharkyenergy
sharkyenergy

Reputation: 4173

Xamarin - Show text if CollectionView empty

I have a CollecitonView that gets populated in the OnAppearing method. This CollectionView is inside a StackLayout, and below the CollectionView I added a label with x:name="hint"

This code populates the CollecitonView

protected override void OnAppearing()
    {
        base.OnAppearing();

        if (!App.galisloaded)
        {
            App.galisloaded = true;
            BindingContext = new GalleryListViewModel();

            (BindingContext as GalleryListViewModel).GetGalleriesCommand.Execute(null);

            ************HERE*************

        }        
    }

I would like in the marked spot to add a counter for the entries, so if there is at least 1 entry in my CollectionView then it should remove visibility from hint. But after 1 hour of trying I cannot figure out how to get the count of my entries.

Upvotes: 0

Views: 670

Answers (1)

Jason
Jason

Reputation: 89169

CollectionView has a built in function to handle empty views

<CollectionView EmptyView="No items to display" ... />

Upvotes: 3

Related Questions