Skip to content

Commit

Permalink
Merge pull request #91 from abbottdev/master
Browse files Browse the repository at this point in the history
Support for DragDropContext #89
  • Loading branch information
punker76 committed Jan 15, 2015
2 parents 268af6b + 8f15499 commit 952b0d5
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Examples/NorthwindExample/Views/EmployeesTabView(NET4).xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}">
<DataGrid.Columns>
<DataGridTextColumn Header="First Name"
Expand All @@ -54,6 +55,8 @@
dd:DragDrop.IsDragSource="True"
dd:DragDrop.IsDropTarget="True"
dd:DragDrop.DropHandler="{Binding}"
dd:DragDrop.DragAdornerTemplate="{x:Null}" />
dd:DragDrop.DragAdornerTemplate="{x:Null}"
dd:DragDrop.DragDropContext="EmployeesNotDroppableFromOther"
/>
</Grid>
</UserControl>
10 changes: 10 additions & 0 deletions GongSolutions.Wpf.DragDrop/DefaultDropHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
24 changes: 24 additions & 0 deletions GongSolutions.Wpf.DragDrop/DragDrop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down Expand Up @@ -865,6 +878,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);
}

Expand Down

0 comments on commit 952b0d5

Please sign in to comment.