ListView drag n drop

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

    Posted 16 Feb Link to this post

    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

     

  2. Lance | Tech Support Engineer, Sr.
    Admin
    Lance | Tech Support Engineer, Sr. avatar
    359 posts

    Posted 20 Feb 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()
            {
                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
Back to Top