Xamarin.forms: CollectionView: EmptyView shown view before items are loaded for the first time

Created on 23 Mar 2020  ·  4Comments  ·  Source: xamarin/Xamarin.Forms

Description

The EmptyView shows immediately together with the refresh spinner.

Steps to Reproduce

  1. Open sample project
  2. Hit Run

Expected Behavior

EmptyView does not show while IsRefreshing is true. At least for the first time.

Actual Behavior

Immediately shows EmptyView

Basic Information

  • Version with issue: 4.5.0.396
  • Last known good version:
  • IDE:
  • Affected Devices: iOS sim

Reproduction Link

EmptyCollectionView.zip

Workaround

Having a boolean inside EmptyView to binded to IsVisible. That way you can control if the EmptyView content is shown at all.

binding ⛓ collectionview Android iOS 🍎 needs-info ❓ unverified bug

Most helpful comment

@hartez Yes. The refreshview is having a spinner indicating that it's loading. So when it's loading you cannot determine if there will be results. Therefor it would make sense if the emptyview is not shown until binded to an actual (empty or not) collection. So if bindablecollection is null, do not show emptyview. Makes sense because that is not an empty collection.

For me an approximation that has worked is inside EmptyView to put a label that points to a property of type string. In my ViewModel, before executing the code that loads the collection linked to the CarouselView, I set the Label property to Loading, then I execute the code that loads the CarouselView and if there is no data I change the property of type string linked to the Label to something that describes what previous.
This works whenever you want the visual aspect of the EmptyView that feeds back the collection load to be the same as the visual aspect that feeds back the fact that there is no data to display. It would be good to have an approach that allows two visual aspects to be established.
Hopefully someone from the Xamarin.Forms team can suggest something else.

All 4 comments

@jantanis You want the CollectionView to remain completely blank until at least one item is loaded. After that, if all of the items are removed, the EmptyView will be visible. Is that correct?

@hartez Yes. The refreshview is having a spinner indicating that it's loading. So when it's loading you cannot determine if there will be results. Therefor it would make sense if the emptyview is not shown until binded to an actual (empty or not) collection. So if bindablecollection is null, do not show emptyview. Makes sense because that is not an empty collection.

@hartez Yes. The refreshview is having a spinner indicating that it's loading. So when it's loading you cannot determine if there will be results. Therefor it would make sense if the emptyview is not shown until binded to an actual (empty or not) collection. So if bindablecollection is null, do not show emptyview. Makes sense because that is not an empty collection.

For me an approximation that has worked is inside EmptyView to put a label that points to a property of type string. In my ViewModel, before executing the code that loads the collection linked to the CarouselView, I set the Label property to Loading, then I execute the code that loads the CarouselView and if there is no data I change the property of type string linked to the Label to something that describes what previous.
This works whenever you want the visual aspect of the EmptyView that feeds back the collection load to be the same as the visual aspect that feeds back the fact that there is no data to display. It would be good to have an approach that allows two visual aspects to be established.
Hopefully someone from the Xamarin.Forms team can suggest something else.

We won't be changing this behavior for a few reasons:

  1. It would be a breaking change for anyone who is already relying on the current behavior.
  2. The current behavior is as designed. Most folks expect that a container with no source of items is going to be empty; this is the intuitive interpretation. I appreciate the semantic argument about a null ItemsSource. But if we change to the behavior you suggest, we'd spend the next several years closing bugs claiming that the CollectionView is broken because setting the ItemsSource to null doesn't show the EmptyView. Also, most users _want_ the refresh animation to display alongside the EmptyView.
  3. For the users who want the alternative, there are multiple simple workarounds (e.g., the binding that you suggested in you original post, or setting the content of the EmptyView at the end of the first Refresh action).
Was this page helpful?
0 / 5 - 0 ratings