[UWP] Is there a reorder items event handler for ListView?

Leisn 6 Reputation points

[UWP ListView]:
Recorder is work well on UI, but I need a way to listen the event.
I found that ObservableCollection has a CollectionChanged event handler, but when recorder completed , an Remove and Add actions emit in pairs.
This is difficult to handle.
I also found ObservableCollection has an action Move, why not just emit Move instead?

And for now, how can I handle that?

Universal Windows Platform (UWP)
0 comments No comments
{count} vote

1 answer

Sort by: Most helpful
  1. Yan Gu - MSFT 2,671 Reputation points


    Welcome to Microsoft Q&A

    When you reorder items in ListView control, you need to drag and drop an item. Dragging an item in ListView will be mapped to a Remove action of ObservableCollection, and dropping an item in ListView will be mapped to a Add action of ObservableCollection. Therefore, an Remove and Add actions emit in pairs when you reorder items by using drag-and-drop interation.

    If you want to listen the reorder event completion, you could add the following if statement to check if the CollectionChanged event handler is called the second time(CollectionChanged event handler completes the Add action) which marks the completion of the reorder.

    You could check the code as a sample:

    private ObservableCollection<string> collections;  
    private int count;  
    private bool flag = false;  
    public MainPage()  
        collections = new ObservableCollection<string>();  
        collections.CollectionChanged += Collections_CollectionChanged;  
        count = collections.Count;  
    private void Collections_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)  
            flag = true;  
            //The reorder completes.  
            flag = false;  

    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments