How to update ListView(SfListView) on property change in .NET MAUI?
You can update the Grouping and Sorting of SfListView on property change by using the LiveDataUpdateMode in the .NET MAUI ListView.
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 an item on ListView
item tapped using the 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";
}
}
}
Download the complete sample from GitHub.
Conclusion
I hope you enjoyed learning how to update the ListView on property change in .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, you can 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. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!