Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for DragDropContext #89 #91

Merged
merged 1 commit into from
Jan 15, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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);
}

Expand Down