Articles in this section
Category / Section

How to update ListView on property change in .NET MAUI (SfListView)?

4 mins read

You can update Grouping and Sorting of SfListView on property change by using LiveDataUpdateMode in .NET MAUI SfListView.

C#
Adding GroupDescriptors, SortDescriptors and LiveDataUpdateMode properties of DataSource to ListView.

namespace ListViewMaui
{
    public class Behavior : Behavior<SfListView>
    {
        SfListView listView;
        protected override void OnAttachedTo(SfListView bindable)
        {
            listView = bindable;
            listView.Loaded += Bindable_Loaded;
            base.OnAttachedTo(bindable);
        }

        private void Bindable_Loaded(object sender, ListViewLoadedEventArgs e)
        {
            listView.DataSource.LiveDataUpdateMode = LiveDataUpdateMode.AllowDataShaping;
            listView.DataSource.GroupDescriptors.Add(
                new GroupDescriptor()
                {
                    PropertyName = "ContactName",
                    KeySelector = (object obj1) =>
                    {
                        var item = (obj1 as Contacts);
                        return item.ContactName[0].ToString();
                    }
                });
            listView.DataSource.SortDescriptors.Add(
                new SortDescriptor()
                {
                    PropertyName = "ContactName"
                });
        }
        protected override void OnDetachingFrom(SfListView bindable)
        {
            listView.Loaded -= Bindable_Loaded;
            listView = null;
            base.OnDetachingFrom(bindable);
        }
    }
}

C#
Modifying item on ListView item tapped on ItemTappedCommand.

namespace ListViewMaui
{
    public class ContactsViewModel : INotifyPropertyChanged
    {
        public Command ChangeItem { get; set; }

        public ContactsViewModel()
        {
            ChangeItem = new Command(OnChangeItem);
        }
        private void OnChangeItem(object obj)
        {
            if((obj as Syncfusion.Maui.ListView.ItemTappedEventArgs).ItemType == ItemType.GroupHeader)
            {
                return;
            }
            var item = (obj as Syncfusion.Maui.ListView.ItemTappedEventArgs).ItemData as Contacts;
            item.ContactName = "Chan";
        }
    }
}

Update_ListView_On_PropertyChanged.gif

View Sample in GitHub

Conclusion
I hope you enjoyed learning about how to update ListView on property change in .NET MAUI SfListView.
You can refer to our .NET MAUI SfListView feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our .NET MAUI SfListView example to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-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