Unplanned
Last Updated: 16 Dec 2023 18:25 by Mark
atlanta
Created on: 18 Jul 2022 12:35
Category: ListView
Type: Feature Request
11
ListView: Provide the option to set custom empty template

An example with CollectionView:

<CollectionView ItemsSource="{Binding EmptyMonkeys}"
                EmptyView="No items to display" />

4 comments
Mark
Posted on: 16 Dec 2023 18:25
This is definitely an expected feature, I not sure why it takes over a year to have something like this implemented.

I have recently purchased the whole suite in good faith and would expect fundamental features to be in place and added quicker than this.
Jason
Posted on: 17 Mar 2023 13:04

Thanks, Didi,

I understand that there are workarounds available. For that matter, I could build all the functionality of your ListView control myself if I wanted to. The point of my comment is that if I'm going to spend $1000 or more on a UI framework, I expect features, not workarounds. Microsoft's built-in CollectionView has the EmptyView option already. It can handle the empty-list state with as little as one line of XAML. I would expect a commercial control to have at least feature parity with what you can get for free. As it stands, your suggested workaround costs around 20 lines of C# plus the required XAML. I'm unimpressed. If I find similar holes in other controls, I won't be buying.

ADMIN
Didi
Posted on: 17 Mar 2023 05:37

Hi Jason,

The ListView does not have an empty template, this is why we have this feature request logged.

However there is an easy way to achieve an empty template:

- When your items source is empty, show the label.
- When the collection is not empty, hide the label.

<Grid>
    <Label IsVisible="{Binding IsListEmpty}" />
  
    <telerikDataControls:RadListView ItemsSource="{Binding MyItems}"/>
</Grid>

There are many ways to check if the list is empty, 

1. Subscribe to ListView.PropertyChnaged and if e.PropertyName == "ItemsSource" then implement a custom logic to display the label. 

2. another option is to use the CollectionChanged event. Here's an example:

public class ViewModel : NotifyPropertyChangedBase
{
    private bool isListEmpty;
 
    public ViewModel()
    {
        MyItems.CollectionChanged += MyItems_CollectionChanged;
    }
 
    private void MyItems_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
    {
        IsListEmpty = MyItems.Count == 0;
    }
 
    public ObservableCollection<string> MyItems { get; set; } = new ObservableCollection<string>();
 
    public bool IsListEmpty
    {
        get => isListEmpty;
        set
        {
            if (isListEmpty == value)
                return;
 
            isListEmpty = value;
            OnPropertyChanged();
        }
    }
}

Regards,
Didi
Progress Telerik

Jason
Posted on: 16 Mar 2023 20:46
I'm testing your UI framework, and the lack of handling for an empty list seems like a huge hole. Am I missing something?