Skip to content

Commit

Permalink
Fix IsSameDragDropContextAsSource calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
punker76 committed Aug 17, 2021
1 parent 2a8d46a commit f62baab
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/GongSolutions.WPF.DragDrop/DropInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ public DropInfo(object sender, DragEventArgs e, [CanBeNull] DragInfo dragInfo, E
this.TargetCollection = tvItem.ItemsSource ?? tvItem.Items;
this.InsertIndex = this.TargetCollection != null ? this.TargetCollection.OfType<object>().Count() : 0;
}

this.InsertPosition |= RelativeInsertPosition.TargetItemCenter;
}
//System.Diagnostics.Debug.WriteLine("==> DropInfo: pos={0}, idx={1}, Y={2}, Item={3}", this.InsertPosition, this.InsertIndex, currentYPos, item);
Expand Down Expand Up @@ -217,6 +218,7 @@ public DropInfo(object sender, DragEventArgs e, [CanBeNull] DragInfo dragInfo, E
this.TargetCollection = tvItem.ItemsSource ?? tvItem.Items;
this.InsertIndex = this.TargetCollection != null ? this.TargetCollection.OfType<object>().Count() : 0;
}

this.InsertPosition |= RelativeInsertPosition.TargetItemCenter;
}
//System.Diagnostics.Debug.WriteLine("==> DropInfo: pos={0}, idx={1}, X={2}, Item={3}", this.InsertPosition, this.InsertIndex, currentXPos, item);
Expand Down Expand Up @@ -282,6 +284,7 @@ public int UnfilteredInsertIndex
}
}
}

return insertIndex;
}
}
Expand Down Expand Up @@ -338,24 +341,23 @@ public bool IsSameDragDropContextAsSource
get
{
// Check if DragInfo stuff exists
if (this.DragInfo == null || this.DragInfo.VisualSource == null)
if (this.DragInfo?.VisualSource is null)
{
return true;
}

// A target should be exists
if (this.VisualTarget == null)
if (this.VisualTarget is null)
{
return true;
}

// Source element has a drag context constraint, we need to check the target property matches.
var sourceContext = this.DragInfo.VisualSource.GetValue(DragDrop.DragDropContextProperty) as string;
if (String.IsNullOrEmpty(sourceContext))
{
return true;
}
var targetContext = this.VisualTarget.GetValue(DragDrop.DragDropContextProperty) as string;
return string.Equals(sourceContext, targetContext);
var sourceContext = DragDrop.GetDragDropContext(this.DragInfo.VisualSource);
var targetContext = DragDrop.GetDragDropContext(this.VisualTarget);

return string.Equals(sourceContext, targetContext)
|| string.IsNullOrEmpty(targetContext);
}
}

Expand All @@ -371,4 +373,4 @@ public enum RelativeInsertPosition
AfterTargetItem = 2,
TargetItemCenter = 4
}
}
}

0 comments on commit f62baab

Please sign in to comment.