punker76/gong-wpf-dragdrop

Dragging between controls creates a shallow copy

matelich opened this issue · 2 comments

When using two databound controls, with editable controls, if you drag an item from one to the other, a shallow copy is made, such that edits to one change the other. While many are opposed to ICloneable for not being strict enough, it is better than nothing and part of .NET.

I added ICloneable support in matelich@564f258 but didn't expand it with a sample, so I haven't submitted a pull request.

Obviously I could fix it with my own drop handler, but it seems like the proper behavior for the default drop handler to me.

@matelich i think it's ok to do this. i would make this

        var sourceList = GetList(dropInfo.DragInfo.SourceCollection);
        var clones = sourceList.OfType<ICloneable>();
        if (clones.Any()) {
          data = clones.Select(c => c.Clone());
        }

instead this

        var sourceList = GetList(dropInfo.DragInfo.SourceCollection);
        if (sourceList[0] is ICloneable) {
          var clones = new ArrayList();
          foreach (ICloneable o in data) {
            clones.Add(o.Clone());
          }
          data = clones;
        }

Great alternative.