diff --git a/GongSolutions.Wpf.DragDrop/Utilities/VisualTreeExtensions.cs b/GongSolutions.Wpf.DragDrop/Utilities/VisualTreeExtensions.cs index 37311f0e..93e0041a 100644 --- a/GongSolutions.Wpf.DragDrop/Utilities/VisualTreeExtensions.cs +++ b/GongSolutions.Wpf.DragDrop/Utilities/VisualTreeExtensions.cs @@ -71,7 +71,8 @@ public static DependencyObject GetVisualAncestor(this DependencyObject d, Type t if (item == itemsControl) { return lastFoundItemByType; } - if (item.GetType() == type || item.GetType().IsSubclassOf(type)) { + if ((item.GetType() == type || item.GetType().IsSubclassOf(type)) + && (itemsControl == null || itemsControl.ItemContainerGenerator.IndexFromContainer(item) >= 0)) { lastFoundItemByType = item; } item = VisualTreeHelper.GetParent(item);