How to show the busy indicator while loading the .NET MAUI ListView ?
The .NET MAUI ListView (SfListView) allows you to display the SfBusyIndicator while loading the bound items. The busy indicator can be enabled and disabled by using the IsRunning property.
XAML
Bind the ViewModel.IsLoading property to the SfBusyIndicator.IsRunning property to enable or disable the busy indicator in the view until items are loaded in the SfListView
<ContentPage xmlns:listview="clr-namespace:Syncfusion.Maui.ListView;assembly=Syncfusion.Maui.ListView" xmlns:busyIndicator="clr-namespace:Syncfusion.Maui.Core;assembly=Syncfusion.Maui.Core”> <Grid> <listview:SfListView x:Name="listView" ItemsSource="{Binding BookInfo}" ItemSize="110"> </listview:SfListView> <busyIndicator:SfBusyIndicator x:Name="busyIndicator" AnimationType="SingleCircle" IsRunning="{Binding IsLoading, Mode=TwoWay}" TextColor="Magenta" SizeFactor="0.5"/> </Grid> </ContentPage>
C#
In behavior class, set the IsLoading property value to true and false based on items generation using the Loaded event.
public class Behavior:Behavior<ContentPage> { SfListView listView; BookInfoViewModel viewModel; protected override void OnAttachedTo(ContentPage bindable) { base.OnAttachedTo(bindable); listView = bindable.FindByName<SfListView>("listView"); viewModel = new BookInfoViewModel(); bindable.BindingContext = viewModel; listView.Loaded += ListView_LoadedAsync; } private async void ListView_LoadedAsync(object sender, ListViewLoadedEventArgs e) { viewModel.IsLoading = true; await Task.Delay(2000); viewModel.GenerateItems(); if (listView.IsLoaded) { viewModel.IsLoading = false; } } protected override void OnDetachingFrom(ContentPage bindable) { base.OnDetachingFrom(bindable); listView = null; viewModel = null; listView.Loaded -= ListView_LoadedAsync; } }
Download the complete sample on GitHub.
I hope you enjoyed learning how to show the busy indicator while loading the .NET MAUI ListView.
You can refer to our .NET MAUI ListView feature tour page to learn about its other groundbreaking feature representations and documentation, and how to quickly get started with configuration specifications. Explore our .NET MAUI ListView demo to understand how to create and manipulate data.
For current customers, check out our components from the License and Downloads page. If you are new to Syncfusion®, try our 30-day free trial to check out our other controls.
Please let us know in the comments section if you have any queries or require clarification. Contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!