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

ListView drag n drop

1 Answer 163 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Luc
Top achievements
Rank 1
Luc asked on 17 Feb 2017, 03:49 AM

Hi,

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?

Thanks

 

1 Answer, 1 is accepted

Sort by
0
Lance | Manager Technical Support
Telerik team
answered on 20 Feb 2017, 09:34 PM
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()
        {
            InitializeComponent();
            myItems.CollectionChanged += myItems_CollectionChanged;
        }
 
        protected override void OnAppearing()
        {
            base.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()
        {
            base.OnDisappearing();
 
            myItems.CollectionChanged -= myItems_CollectionChanged;
        }
 
        private void myItems_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            switch (e.Action)
            {
                case NotifyCollectionChangedAction.Add:
                    break;
                case NotifyCollectionChangedAction.Move:
                    break;
                case NotifyCollectionChangedAction.Remove:
                    break;
                case NotifyCollectionChangedAction.Replace:
                    break;
                case NotifyCollectionChangedAction.Reset:
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }
        }
}


Regards,
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
Tags
ListView
Asked by
Luc
Top achievements
Rank 1
Answers by
Lance | Manager Technical Support
Telerik team
Share this question
or