|
| 1 | +--- |
| 2 | +title: Removing ManualLoadOnDemandTemplate in CollectionView for .NET MAUI When No More Items Are Available |
| 3 | +description: Learn how to remove or hide the ManualLoadOnDemandTemplate in CollectionView for .NET MAUI when there are no more items to load. |
| 4 | +type: how-to |
| 5 | +page_title: Hiding CollectionView ManualLoadOnDemandTemplate When No More Items to Load in .NET MAUI |
| 6 | +meta_title: Hiding CollectionView ManualLoadOnDemandTemplate When No More Items to Load in .NET MAUI |
| 7 | +slug: removing-manualloadondemandtemplate-collectionview-dotnet-maui |
| 8 | +tags: collectionview, .net maui, manualloadondemandtemplate, isloadondemandenabled |
| 9 | +res_type: kb |
| 10 | +--- |
| 11 | + |
| 12 | +## Environment |
| 13 | + |
| 14 | +| Version | Product | Author | |
| 15 | +| --- | --- | ---- | |
| 16 | +| 11.0.0 | Telerik UI for .NET MAUI CollectionView | [Dobrinka Yordanova](https://www.telerik.com/blogs/author/dobrinka-yordanova) | |
| 17 | + |
| 18 | +## Description |
| 19 | + |
| 20 | +I want the `ManualLoadOnDemandTemplate` of the [CollectionView]({%slug collectionview-overview%}) 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. |
| 21 | + |
| 22 | +This knowledge base article also answers the following questions: |
| 23 | +- How can I disable the `ManualLoadOnDemandTemplate` in CollectionView for .NET MAUI? |
| 24 | +- What property controls the visibility of the `ManualLoadOnDemandTemplate` in CollectionView? |
| 25 | +- How do I stop the load-on-demand feature in CollectionView for .NET MAUI? |
| 26 | + |
| 27 | +## Solution |
| 28 | + |
| 29 | +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`. |
| 30 | + |
| 31 | +Here is an example: |
| 32 | + |
| 33 | +**1.** Define the `ViewModel` |
| 34 | + |
| 35 | +```csharp |
| 36 | +public partial class LoadOnDemandCollectionViewModel : NotifyPropertyChangedBase |
| 37 | +{ |
| 38 | + private bool isEnabled = true; |
| 39 | + |
| 40 | + public LoadOnDemandCollectionViewModel() |
| 41 | + { |
| 42 | + this.Items = new LoadOnDemandCollection<Person>(this.LoadMoreItems); |
| 43 | + |
| 44 | + for (int i = 0; i < 20; i++) |
| 45 | + { |
| 46 | + this.Items.Add(new Person { Name = "Person " + i, Age = i + 10 }); |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + public LoadOnDemandCollection<Person> Items { get; set; } |
| 51 | + |
| 52 | + public bool IsEnabled |
| 53 | + { |
| 54 | + get => this.isEnabled; |
| 55 | + set => this.UpdateValue(ref this.isEnabled, value); |
| 56 | + } |
| 57 | + |
| 58 | + private IEnumerable LoadMoreItems(CancellationToken cancellationToken) |
| 59 | + { |
| 60 | + List<Person> newItems = new List<Person>(); |
| 61 | + int count = this.Items.Count; |
| 62 | + |
| 63 | + // Simulate a limit for loading more items |
| 64 | + if (count >= 30) |
| 65 | + { |
| 66 | + this.IsEnabled = false; // Disable load-on-demand |
| 67 | + return null; // No more items to load |
| 68 | + } |
| 69 | + |
| 70 | + for (int i = count; i < count + 10; i++) |
| 71 | + { |
| 72 | + newItems.Add(new Person { Name = "Person " + i, Age = i + 10 }); |
| 73 | + } |
| 74 | + |
| 75 | + return newItems; |
| 76 | + } |
| 77 | +} |
| 78 | +``` |
| 79 | + |
| 80 | +**2.** Bind the `IsLoadOnDemandEnabled` property of the `RadCollectionView` to a property in your ViewModel, such as `IsEnabled`: |
| 81 | + |
| 82 | +```xml |
| 83 | +<telerik:RadCollectionView x:Name="listView" |
| 84 | + ItemsSource="{Binding Items}" |
| 85 | + DisplayMemberPath="Name" |
| 86 | + LoadOnDemandMode="Manual" |
| 87 | + IsLoadOnDemandEnabled="{Binding IsEnabled, Mode=TwoWay}" /> |
| 88 | +``` |
| 89 | + |
| 90 | +## See Also |
| 91 | + |
| 92 | +- [CollectionView Overview]({%slug collectionview-overview%}) |
| 93 | +- [Load on Demand in .NET MAUI CollectionView]({%slug collectionview-load-on-demand%}) |
0 commit comments