diff --git a/Examples/DefaultsExample/Window(NET4).xaml b/Examples/DefaultsExample/Window(NET4).xaml index 37097042..81bb8f69 100644 --- a/Examples/DefaultsExample/Window(NET4).xaml +++ b/Examples/DefaultsExample/Window(NET4).xaml @@ -546,6 +546,7 @@ diff --git a/GongSolutions.Wpf.DragDrop/DragDrop.cs b/GongSolutions.Wpf.DragDrop/DragDrop.cs index 656781c6..9fe52657 100644 --- a/GongSolutions.Wpf.DragDrop/DragDrop.cs +++ b/GongSolutions.Wpf.DragDrop/DragDrop.cs @@ -267,6 +267,19 @@ public static void SetDragSourceIgnore(UIElement target, bool value) target.SetValue(DragSourceIgnoreProperty, value); } + public static readonly DependencyProperty DragDirectlySelectedOnlyProperty = + DependencyProperty.RegisterAttached("DragDirectlySelectedOnly", typeof(bool), typeof(DragDrop), new PropertyMetadata(false)); + + public static bool GetDragDirectlySelectedOnly(DependencyObject obj) + { + return (bool)obj.GetValue(DragDirectlySelectedOnlyProperty); + } + + public static void SetDragDirectlySelectedOnly(DependencyObject obj, bool value) + { + obj.SetValue(DragDirectlySelectedOnlyProperty, value); + } + /// /// DragMouseAnchorPoint defines the horizontal and vertical proportion at which the pointer will anchor on the DragAdorner. /// diff --git a/GongSolutions.Wpf.DragDrop/DragInfo.cs b/GongSolutions.Wpf.DragDrop/DragInfo.cs index 2d790116..aebacb33 100644 --- a/GongSolutions.Wpf.DragDrop/DragInfo.cs +++ b/GongSolutions.Wpf.DragDrop/DragInfo.cs @@ -52,8 +52,12 @@ public DragInfo(object sender, MouseButtonEventArgs e) if (sourceItem != null) { item = itemsControl.GetItemContainer(sourceItem); } + if (item == null) { - item = itemsControl.GetItemContainerAt(e.GetPosition(itemsControl), itemsControl.GetItemsPanelOrientation()); + if (DragDrop.GetDragDirectlySelectedOnly(VisualSource)) + item = itemsControl.GetItemContainerAt(e.GetPosition(itemsControl)); + else + item = itemsControl.GetItemContainerAt(e.GetPosition(itemsControl), itemsControl.GetItemsPanelOrientation()); } if (item != null) {