Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[Enhancement] EmptyView for BindableLayout #6932

Closed
hartez opened this issue Jul 19, 2019 · 2 comments · Fixed by #7686
Closed

[Enhancement] EmptyView for BindableLayout #6932

hartez opened this issue Jul 19, 2019 · 2 comments · Fixed by #7686
Labels
a/bindablelayout in-progress This issue has an associated pull request that may resolve it! proposal-accepted t/enhancement ➕

Comments

@hartez
Copy link
Contributor

hartez commented Jul 19, 2019

Summary

Add an EmptyView property to BindableLayout which, when set, displays if there are no other items in the layout.

This is basically a duplicate of the EmptyView feature on CollectionView.

API Changes

In BindableLayout, add:

public static readonly BindableProperty EmptyViewProperty = BindableProperty.Create(nameof(EmptyView), typeof(object), typeof(Layout<View>), null);

public static readonly BindableProperty EmptyViewTemplateProperty = BindableProperty.Create(nameof(EmptyViewTemplate), typeof(DataTemplate), typeof(Layout<View>), null);

Intended Use Case

In the following example, if ItemsSource contains any items, they will be displayed in the StackLayout and EmptyView will not be visible. If ItemSource contains no items, the EmptyView will be displayed as the sole element in the StackLayout.

<StackLayout BindableLayout.ItemsSource="{Binding ItemsSource}">
    <BindableLayout.EmptyView>
        <Label Text="No Results"/>
    </BindableLayout.EmptyView>
</StackLayout>

If EmptyViewTemplate is set, the template content will be displayed with EmptyView as the binding context for the template content.

If EmptyViewTemplate is not set, the following rules apply:

  • If the content of EmptyView is a simple string, that string is displayed as a Label.
  • If the content of EmptyView is a Forms element, that element is displayed.
  • Otherwise, the EmptyView object's ToString(InvariantCulture) representation is displayed as a Label.
@Eilon
Copy link
Contributor

Eilon commented Jul 19, 2019

I am a Xamarin Forms user, and I approve this message.

@ChaseFlorell
Copy link

I was just coming here to ask for the same thing!

Right now we use this, and it's ugly and a pain.

<StackLayout BindableLayout.ItemsSource="{Binding SomeList}">
    <!-- -->
</StackLayout>
<Label Text="No Results" IsVisible="{Binding SomeList, Converter={StaticResource HasValueConverter}}"

@samhouts samhouts added in-progress This issue has an associated pull request that may resolve it! and removed a/collectionview labels Sep 26, 2019
rmarinho added a commit that referenced this issue Feb 4, 2020
* Update BindableLayoutGalleryPage.xaml

* Added demo

* Account for null and added tests

* Big cleanup

* Update BindableLayout.cs

* Update BindableLayoutGalleryPage.xaml

Co-authored-by: Rui Marinho <me@ruimarinho.net>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
a/bindablelayout in-progress This issue has an associated pull request that may resolve it! proposal-accepted t/enhancement ➕
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants