diff --git a/src/GongSolutions.WPF.DragDrop/DragDrop.cs b/src/GongSolutions.WPF.DragDrop/DragDrop.cs index 90cf8dc8..42dd7d1f 100644 --- a/src/GongSolutions.WPF.DragDrop/DragDrop.cs +++ b/src/GongSolutions.WPF.DragDrop/DragDrop.cs @@ -444,13 +444,6 @@ private static void DoMouseButtonUp(object sender, MouseButtonEventArgs e) private static void DragSourceUp(object sender, Point elementPosition) { - if (sender is TabControl && !HitTestUtilities.HitTest4Type(sender, elementPosition)) - { - _dragInfo = null; - _clickSupressItem = null; - return; - } - var dragInfo = _dragInfo; // If we prevented the control's default selection handling in DragSource_PreviewMouseLeftButtonDown diff --git a/src/GongSolutions.WPF.DragDrop/DropInfo.cs b/src/GongSolutions.WPF.DragDrop/DropInfo.cs index e380e4b9..7df8c95a 100644 --- a/src/GongSolutions.WPF.DragDrop/DropInfo.cs +++ b/src/GongSolutions.WPF.DragDrop/DropInfo.cs @@ -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().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); @@ -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().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); @@ -282,6 +284,7 @@ public int UnfilteredInsertIndex } } } + return insertIndex; } } @@ -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); } } @@ -371,4 +373,4 @@ public enum RelativeInsertPosition AfterTargetItem = 2, TargetItemCenter = 4 } -} +} \ No newline at end of file diff --git a/src/GongSolutions.WPF.DragDrop/Utilities/VisualTreeExtensions.cs b/src/GongSolutions.WPF.DragDrop/Utilities/VisualTreeExtensions.cs index f64b7305..8e614f44 100644 --- a/src/GongSolutions.WPF.DragDrop/Utilities/VisualTreeExtensions.cs +++ b/src/GongSolutions.WPF.DragDrop/Utilities/VisualTreeExtensions.cs @@ -148,11 +148,23 @@ public static DependencyObject GetVisualAncestor(this DependencyObject d, Type i public static T GetVisualDescendent(this DependencyObject d) where T : DependencyObject { - return d.GetVisualDescendents().FirstOrDefault(); + return d.GetVisualDescendents(null).FirstOrDefault(); + } + + public static T GetVisualDescendent(this DependencyObject d, string childName) + where T : DependencyObject + { + return d.GetVisualDescendents(childName).FirstOrDefault(); } public static IEnumerable GetVisualDescendents(this DependencyObject d) where T : DependencyObject + { + return d.GetVisualDescendents(null); + } + + public static IEnumerable GetVisualDescendents(this DependencyObject d, string childName) + where T : DependencyObject { var childCount = VisualTreeHelper.GetChildrenCount(d); @@ -160,12 +172,16 @@ public static IEnumerable GetVisualDescendents(this DependencyObject d) { var child = VisualTreeHelper.GetChild(d, n); - if (child is T) + if (child is T descendent) { - yield return (T)child; + if (string.IsNullOrEmpty(childName) + || descendent is IFrameworkInputElement frameworkInputElement && frameworkInputElement.Name == childName) + { + yield return descendent; + } } - foreach (var match in GetVisualDescendents(child)) + foreach (var match in GetVisualDescendents(child, childName)) { yield return match; } diff --git a/src/Showcase/Views/Issues.xaml b/src/Showcase/Views/Issues.xaml index f944abb1..f421f3b3 100644 --- a/src/Showcase/Views/Issues.xaml +++ b/src/Showcase/Views/Issues.xaml @@ -1050,6 +1050,88 @@ + + + + +