RadListView EmptyView

1 Answer 169 Views
ListView
Angelica
Top achievements
Rank 1
Iron
Angelica asked on 04 Aug 2023, 01:11 PM

Good morning,

Is there a way to format/customize what the empty view looks like? Currently it just says "No data", I wasn't sure if it was possible to add a custom message/style.

Thank you!

 

1 Answer, 1 is accepted

Sort by
0
Lance | Senior Manager Technical Support
Telerik team
answered on 04 Aug 2023, 05:49 PM

Hello Angelica,

This is not currently available as a .NET MAUI-layer capability because not all of the native platforms have the empty content feature.

If you're on Windows, which is appears to be from the screenshot, then you can use the .NET MAUI platform handler to access the native ListView control. Once you have a reference to the native control, you can customize the content through the EmptyContent property.

If you're not familiar with how to use handlers, here's a demo. Notice you need to subscribe to the .NET MAUI control's HandlerChanged event in order to know exactly when in the lifecycle you can set this up.

public partial class MainPage : ContentPage
{
    public MainPage()
    {
        InitializeComponent();

        NamesListView.HandlerChanged += NamesListView_HandlerChanged;
    }

    private void NamesListView_HandlerChanged(object sender, EventArgs e)
    {
        if (NamesListView.Handler == null)
            return;

        var mauiListView = sender as Telerik.Maui.Controls.Compatibility.DataControls.RadListView;

        #if WINDOWS

        // Get a reference to the native RadListView from Telerik UI for WinUI.
        // IMPORTANT: Be very careful with the namespaces because "RadListView" exists in both .NET MAUI and in WinUI 3
        if (mauiListView?.Handler?.PlatformView is Telerik.UI.Xaml.Controls.Data.RadListView windowsListView)
        {
            // IMPORTANT: the EmptyContent must be native WinUI content... not .NET MAUI content!
            windowsListView.EmptyContent = new Microsoft.UI.Xaml.Controls.TextBlock { Text = "Hello, there are no names available" };
        }
        
        #endif
    }
}

 

To learn more about the features of the native Windows RadListView control, please visit the Telerik UI for WinUI documentation => RadListView Overview - WinUI Control - Telerik UI for WinUI

Regards,
Lance | Manager Technical Support
Progress Telerik

A brand new .NET MAUI course was just added to the Virtual Classroom. The training course is developed to help you get started with the Telerik UI for .NET MAUI components and features. It aims to put you in the shoes of an engineer who adds new features to an existing application. You can check it out at https://learn.telerik.com
Mark
Top achievements
Rank 3
Iron
Iron
Iron
commented on 16 Dec 2023, 06:30 PM

I get the work-around, but really, come on guys this is fundamental features that should have been noticed when testing with no results, and sure "No data" should at least be customisable. These are Controls for building into 'our' apps that should be totally configurable, this is why we buy them.
Mark
Top achievements
Rank 3
Iron
Iron
Iron
commented on 16 Dec 2023, 06:35 PM

If work-arounds are provided, can we have the work-around for all platforms, since this is the nature of the controls?
Otherwise we need to have the same battle for all of them.
Mark
Top achievements
Rank 3
Iron
Iron
Iron
commented on 17 Dec 2023, 05:53 PM

Having needed content on an empty list, just hide the list and show a label or other content, much easier
Tags
ListView
Asked by
Angelica
Top achievements
Rank 1
Iron
Answers by
Lance | Senior Manager Technical Support
Telerik team
Share this question
or