ListView drag n drop

2 posts, 0 answers
  1. Luc
    Luc avatar
    3 posts
    Member since:
    Feb 2017

    Posted 16 Feb 2017 Link to this post


    I'm using a drag n drop ListView (IsItemsReorderEnabled=True). works fine.

    Just wondering can the selected Item has a different style? also is there a event that once we release  the item?



  2. Lance | Manager Technical Support
    Lance | Manager Technical Support avatar
    1193 posts

    Posted 20 Feb 2017 Link to this post

    Hello Luc,

    See here on how to style the RadListViewItem. You can have a style for Selected, Normal and Pressed.

    As far as needing an event for when the item is released, you can do this by hooking into the ListView's bound items source as long as you're using an ObservableCollection<T>.

    The ObservableCollection has a CollectionChanged event. This will fire because the ListView has reordered the items in the bound ObservableCollection and in the event handler you can detect what change occurred and act accordingly.

    See the switch statement in the CollectionChanged event handler in this theoretical example: 

    public partial class StartPage : ContentPage
            private ObservableCollection<string> myItems;
            public StartPage()
                myItems.CollectionChanged += myItems_CollectionChanged;
            protected override void OnAppearing()
                myItems.CollectionChanged += myItems_CollectionChanged;
                myItems = new ObservableCollection<string>();
                for (int i = 0; i < 10; i++)
                    myItems.Add($"Item {i}");
                myListView.ItemsSource = myItems;
            protected override void OnDisappearing()
                myItems.CollectionChanged -= myItems_CollectionChanged;
            private void myItems_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
                switch (e.Action)
                    case NotifyCollectionChangedAction.Add:
                    case NotifyCollectionChangedAction.Move:
                    case NotifyCollectionChangedAction.Remove:
                    case NotifyCollectionChangedAction.Replace:
                    case NotifyCollectionChangedAction.Reset:
                        throw new ArgumentOutOfRangeException();

    Lance | Tech Support Engineer, Sr.
    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
Back to Top