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

Added DragDirectlySelectedOnly #120

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
1 change: 1 addition & 0 deletions Examples/DefaultsExample/Window(NET4).xaml
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,7 @@
<TabItem Header="ListBox with Groups">
<ListBox ItemsSource="{Binding Source={StaticResource GroupedCollectionViewSource}}"
DisplayMemberPath="Caption"
dd:DragDrop.DragDirectlySelectedOnly="True"
dd:DragDrop.IsDragSource="True"
dd:DragDrop.IsDropTarget="True"
dd:DragDrop.DropHandler="{Binding}">
Expand Down
13 changes: 13 additions & 0 deletions GongSolutions.Wpf.DragDrop/DragDrop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/// <summary>
/// DragMouseAnchorPoint defines the horizontal and vertical proportion at which the pointer will anchor on the DragAdorner.
/// </summary>
Expand Down
6 changes: 5 additions & 1 deletion GongSolutions.Wpf.DragDrop/DragInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down