From ee1d97e74ab88f95158d15e6686b6c25d6a62781 Mon Sep 17 00:00:00 2001 From: Gerrit van Roekel Date: Wed, 11 Feb 2015 21:06:48 +0100 Subject: [PATCH] Fix an issue when the itempresenter contains more ContentControl, for example: Label / ScrollViewer / Expander. --- GongSolutions.Wpf.DragDrop/Utilities/VisualTreeExtensions.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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);