Removing ManualLoadOnDemandTemplate in CollectionView for .NET MAUI When No More Items Are Available
Environment
Version | Product | Author |
---|---|---|
11.0.0 | Telerik UI for .NET MAUI CollectionView | Dobrinka Yordanova |
Description
I want the ManualLoadOnDemandTemplate
of the CollectionView for .NET MAUI to disappear when there are no more items to load. The template currently remains visible even after all data has been loaded.
This knowledge base article also answers the following questions:
- How can I disable the
ManualLoadOnDemandTemplate
in CollectionView for .NET MAUI? - What property controls the visibility of the
ManualLoadOnDemandTemplate
in CollectionView? - How do I stop the load-on-demand feature in CollectionView for .NET MAUI?
Solution
To remove or hide the ManualLoadOnDemandTemplate
when no more items need to be loaded, set the IsLoadOnDemandEnabled
property of the CollectionView to false
. This property controls whether the load-on-demand functionality is active. Disabling it hides the ManualLoadOnDemandTemplate
.
Here is an example:
1. Define the ViewModel
public partial class LoadOnDemandCollectionViewModel : NotifyPropertyChangedBase
{
private bool isEnabled = true;
public LoadOnDemandCollectionViewModel()
{
this.Items = new LoadOnDemandCollection<Person>(this.LoadMoreItems);
for (int i = 0; i < 20; i++)
{
this.Items.Add(new Person { Name = "Person " + i, Age = i + 10 });
}
}
public LoadOnDemandCollection<Person> Items { get; set; }
public bool IsEnabled
{
get => this.isEnabled;
set => this.UpdateValue(ref this.isEnabled, value);
}
private IEnumerable LoadMoreItems(CancellationToken cancellationToken)
{
List<Person> newItems = new List<Person>();
int count = this.Items.Count;
// Simulate a limit for loading more items
if (count >= 30)
{
this.IsEnabled = false; // Disable load-on-demand
return null; // No more items to load
}
for (int i = count; i < count + 10; i++)
{
newItems.Add(new Person { Name = "Person " + i, Age = i + 10 });
}
return newItems;
}
}
2. Bind the IsLoadOnDemandEnabled
property of the RadCollectionView
to a property in your ViewModel, such as IsEnabled
:
<telerik:RadCollectionView x:Name="listView"
ItemsSource="{Binding Items}"
DisplayMemberPath="Name"
LoadOnDemandMode="Manual"
IsLoadOnDemandEnabled="{Binding IsEnabled, Mode=TwoWay}" />