diff --git a/Examples/NorthwindExample/Views/EmployeesTabView(NET4).xaml b/Examples/NorthwindExample/Views/EmployeesTabView(NET4).xaml index 80ce4553..4c1541d4 100644 --- a/Examples/NorthwindExample/Views/EmployeesTabView(NET4).xaml +++ b/Examples/NorthwindExample/Views/EmployeesTabView(NET4).xaml @@ -37,6 +37,7 @@ dd:DragDrop.IsDropTarget="True" dd:DragDrop.DropHandler="{Binding}" dd:DragDrop.DragAdornerTemplate="{x:Null}" + dd:DragDrop.DragDropContext="Employees" dd:DragDrop.EffectNoneAdornerTemplate="{x:Null}"> + dd:DragDrop.DragAdornerTemplate="{x:Null}" + dd:DragDrop.DragDropContext="EmployeesNotDroppableFromOther" + /> diff --git a/GongSolutions.Wpf.DragDrop/DefaultDropHandler.cs b/GongSolutions.Wpf.DragDrop/DefaultDropHandler.cs index 76094f12..a76bfec9 100644 --- a/GongSolutions.Wpf.DragDrop/DefaultDropHandler.cs +++ b/GongSolutions.Wpf.DragDrop/DefaultDropHandler.cs @@ -53,6 +53,16 @@ public static bool CanAcceptData(IDropInfo dropInfo) return false; } + if (!String.IsNullOrEmpty((string)dropInfo.DragInfo.VisualSource.GetValue(DragDrop.DragDropContextProperty))) + { + //Source element has a drag context constraint, we need to check the target property matches. + var sourceContext = (string)dropInfo.DragInfo.VisualSource.GetValue(DragDrop.DragDropContextProperty); + var targetContext = (string)dropInfo.VisualTarget.GetValue(DragDrop.DragDropContextProperty); + + if (!string.Equals(sourceContext, targetContext)) + return false; + } + if (dropInfo.DragInfo.SourceCollection == dropInfo.TargetCollection) { return GetList(dropInfo.TargetCollection) != null; } else if (dropInfo.DragInfo.SourceCollection is ItemCollection) { diff --git a/GongSolutions.Wpf.DragDrop/DragDrop.cs b/GongSolutions.Wpf.DragDrop/DragDrop.cs index 09da0e80..b98864bc 100644 --- a/GongSolutions.Wpf.DragDrop/DragDrop.cs +++ b/GongSolutions.Wpf.DragDrop/DragDrop.cs @@ -228,6 +228,19 @@ public static void SetIsDropTarget(UIElement target, bool value) target.SetValue(IsDropTargetProperty, value); } + public static readonly DependencyProperty DragDropContextProperty = + DependencyProperty.RegisterAttached("DragDropContext", typeof(string), typeof(DragDrop), new UIPropertyMetadata(string.Empty)); + + public static string GetDragDropContext(UIElement target) + { + return (string)target.GetValue(DragDropContextProperty); + } + + public static void SetDragDropContext(UIElement target, string value) + { + target.SetValue(DragDropContextProperty, value); + } + public static readonly DependencyProperty DragHandlerProperty = DependencyProperty.RegisterAttached("DragHandler", typeof(IDragSource), typeof(DragDrop)); @@ -815,6 +828,17 @@ private static void DropTarget_PreviewDragOver(object sender, DragEventArgs e) e.Effects = dropInfo.Effects; e.Handled = !dropInfo.NotHandled; + if (!string.IsNullOrEmpty((string)dropInfo.DragInfo.VisualSource.GetValue(DragDrop.DragDropContextProperty))) + { + var sourceContext = (string)dropInfo.DragInfo.VisualSource.GetValue(DragDrop.DragDropContextProperty); + var targetContext = (string)dropInfo.VisualTarget.GetValue(DragDrop.DragDropContextProperty); + + if (!string.IsNullOrEmpty(targetContext) && !string.Equals(sourceContext, targetContext)) + { + e.Effects = DragDropEffects.None; + } + } + Scroll((DependencyObject)dropInfo.VisualTarget, e); }