Skip to content

Commit

Permalink
Merge branch 'develop' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
punker76 committed Sep 20, 2021
2 parents 864eab6 + af76cba commit 2a93cac
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions src/GongSolutions.WPF.DragDrop/DefaultDropHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,16 +167,16 @@ public virtual void Drop(IDropInfo dropInfo)
var insertIndex = GetInsertIndex(dropInfo);
var destinationList = dropInfo.TargetCollection.TryGetList();
var data = ExtractData(dropInfo.Data).OfType<object>().ToList();
bool forceMoveBehavior = false;
bool isSameCollection = false;

var copyData = ShouldCopyData(dropInfo);
if (!copyData)
{
var sourceList = dropInfo.DragInfo.SourceCollection.TryGetList();
if (sourceList != null)
{
forceMoveBehavior = sourceList.IsSameObservableCollection(destinationList);
if (!forceMoveBehavior)
isSameCollection = sourceList.IsSameObservableCollection(destinationList);
if (!isSameCollection)
{
foreach (var o in data)
{
Expand Down Expand Up @@ -216,15 +216,18 @@ public virtual void Drop(IDropInfo dropInfo)

objects2Insert.Add(obj2Insert);

if (!cloneData && forceMoveBehavior)
if (!cloneData && isSameCollection)
{
var index = destinationList.IndexOf(o);
if (insertIndex > index)
if (index != -1)
{
insertIndex--;
}
if (insertIndex > index)
{
insertIndex--;
}

Move(destinationList, index, insertIndex++);
Move(destinationList, index, insertIndex++);
}
}
else
{
Expand Down Expand Up @@ -266,8 +269,11 @@ protected static void Move(IList list, int sourceIndex, int destinationIndex)
throw new ArgumentException("ObservableCollection<T> was expected", nameof(list));
}

var method = list.GetType().GetMethod("Move", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);
method.Invoke(list, new object[] { sourceIndex, destinationIndex });
if (sourceIndex != destinationIndex)
{
var method = list.GetType().GetMethod("Move", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);
_ = method?.Invoke(list, new object[] { sourceIndex, destinationIndex });
}
}

protected static bool IsChildOf(UIElement targetItem, UIElement sourceItem)
Expand Down

0 comments on commit 2a93cac

Please sign in to comment.