How do we use ChildrenReordered event?

3 posts, 0 answers
  1. Ron
    Ron avatar
    18 posts
    Member since:
    Jan 2017

    Posted 15 Feb Link to this post

    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. Ves
    Admin
    Ves avatar
    2914 posts

    Posted 20 Feb Link to this post

    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
  3. Ron
    Ron avatar
    18 posts
    Member since:
    Jan 2017

    Posted 20 Feb in reply to Ves Link to this post

    Awesome! Thank you!
Back to Top