Skip to content

Wrong ObservableCollection EventArg after drag/drop #355

Closed

Description

@tonecool

I'm using ObservableCollection which is bound to ItemsControl ItemsSource property.

What I expect to get after drag and drop an item within control is NotifyCollectionChangedAction.Move event like this:

        private void MyCollection_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (e.Action == NotifyCollectionChangedAction.Move)
            {
                //DO something
            }
        }

But instead I'm getting two events (NotifyCollectionChangedAction.Remove and NotifyCollectionChangedAction.Add). I'm not sure if this is by design but in my case it was complicating the logic to decide if there was new item added externally or just drag/dropped existing control item.

Repo

I can provide code example if needed.

Environment

  • GongSolutions.WPF.DragDrop 2.2.0
  • Windows 10
  • Visual Studio 2019
  • .NET Framework 4.7.2

Activity

  1. punker76 commented on Oct 17, 2020

    @punker76
    Owner

    @tonecool I think that's because the default drop handler uses the RemoveAt and Insert methods of the source and destination. If you know that's always the same then you can implement your own drop handler which then uses the move method. If you find a solution then you can try to add this here and make a PR. Thx 🙏

  2. Mogikan commented on Oct 29, 2020

    @Mogikan
    Contributor

    Use case when it's important: you need to implement Undo/Redo. Because when you undo it deletes an item, but does not paste it back.

  3. added this to the 2.4.0 milestone on Nov 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions