This is a migrated thread and some comments may be shown as answers.

How do we use ChildrenReordered event?

2 Answers 204 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Ron
Top achievements
Rank 1
Ron asked on 15 Feb 2017, 07:02 PM

I need to know when the list has been reordered. I see that there is a ChildrenReordered event, but I can't get it to fire. Would you please provide the code behind C# code to handle when the list has been reordered?

Thanks!

2 Answers, 1 is accepted

Sort by
0
Ves
Telerik team
answered on 20 Feb 2017, 11:59 AM
Hi Ron,

ChildrenReordered event is exposed by Xamarin.Forms.VisualElement and it is not applicable in this case. Instead, you can handle the CollectionChanged event of the ItemsSource, provided, that the items source is an observable collection. The CollectionChanged event will be triggered twice -- once with Remove action and second time with Add. Here is a sample:

public lv000()
        {
            InitializeComponent();
 
            this.listView.ItemsSource = new ObservableCollection<string>(from c in Enumerable.Range(0, 50) select "Item " + c);
            (this.listView.ItemsSource as ObservableCollection<string>).CollectionChanged += Lv000_CollectionChanged;
             
            this.listView.IsItemsReorderEnabled = true;
        }
 
        private void Lv000_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Remove)
            {
                var removedItem = e.OldItems[0];
            }
            else if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
            {
                var addedItem = e.NewItems[0];
            }
             
        }


Best regards,
Ves
Telerik by Progress
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Ron
Top achievements
Rank 1
answered on 20 Feb 2017, 01:58 PM
Awesome! Thank you!
Tags
ListView
Asked by
Ron
Top achievements
Rank 1
Answers by
Ves
Telerik team
Ron
Top achievements
Rank 1
Share this question
or