Skip to content

This repository contains sample about how to update ListView on property change in Xamarin.Forms (SfListView)

Notifications You must be signed in to change notification settings

SyncfusionExamples/listview-property-change-update-xamarin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

How to update ListView on property change in Xamarin.Forms (SfListView)

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

You can also refer the following article

https://www.syncfusion.com/kb/11419/how-to-update-listview-on-property-change-in-xamarin-forms-sflistview

C#

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

namespace ListViewXamarin
{
    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

namespace ListViewXamarin
{
    public class ContactsViewModel : INotifyPropertyChanged
    {
        public Command ChangeItem { get; set; }
 
        public ContactsViewModel()
        {
            ChangeItem = new Command(OnChangeItem);
        }
        private void OnChangeItem(object obj)
        {
            if((obj as Syncfusion.ListView.XForms.ItemTappedEventArgs).ItemType == ItemType.GroupHeader)
            {
                return;
            }
            var item = (obj as Syncfusion.ListView.XForms.ItemTappedEventArgs).ItemData as Contacts;
            item.ContactName = "Chan";
        }
    }
}

Output

PropertyChangeListview

About

This repository contains sample about how to update ListView on property change in Xamarin.Forms (SfListView)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages