Articles in this section
Category / Section

How to refresh items at runtime using Timer in .NET MAUI ListView(SfListView) ?

3 mins read

The .NET MAUI ListView allows you to refresh items at runtime by updating the ItemsSource at specific time intervals using the PropertyChanged event.

The following example illustrates how to change the ItemsSource using the PropertyChanged event by timer.

C#

public class Behavior : Behavior<ContentPage>
{
   #region Fields
    private Syncfusion.Maui.ListView.SfListView listView;
   #endregion
 
  #region Overrides
  protected override void OnAttachedTo(ContentPage bindable)
  {
      InitializeTimer();
      listView = bindable.FindByName<Syncfusion.Maui.ListView.SfListView>("listView");
      listView.PropertyChanged += ListView_PropertyChanged;
      base.OnAttachedTo(bindable);
  }
  private void ListView_PropertyChanged(object sender, PropertyChangedEventArgs e)
  {
      if (e.PropertyName == "ItemsSource")
          InitializeTimer();
  }
 private async void InitializeTimer()
 {
    await WaitAndExecute(2000, () =>
    {
        var viewmodel = new ContactInfoRepository();
        listView.ItemsSource = viewmodel.ContactInfo;
    });
 }
 private async Task WaitAndExecute(int milisec, Action actionToExecute)
 {
    await Task.Delay(milisec);
    actionToExecute();
 }
 protected override void OnDetachingFrom(ContentPage bindable)
 {
     listView = null;
     base.OnDetachingFrom(bindable);
 }
 #endregion
}

Download the complete sample on GitHub

Conclusion

I hope you enjoyed learning how to refresh items at runtime using a timer in the .NET MAUI ListView.

You can refer to our .NET MAUI ListView feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started with configuration specifications. Explore our .NET MAUI ListView example 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 forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied