Skip to content

Commit 0e8526b

Browse files
committed
another little fix with grouping
1 parent 3ab693e commit 0e8526b

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

GongSolutions.Wpf.DragDrop/DropInfo.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,16 @@ public DropInfo(object sender, DragEventArgs e, DragInfo dragInfo)
7272
directlyOverItem = false;
7373
}
7474

75+
if (item == null && this.TargetGroup != null && this.TargetGroup.IsBottomLevel)
76+
{
77+
var itemData = this.TargetGroup.Items.FirstOrDefault();
78+
if (itemData != null)
79+
{
80+
item = itemsControl.ItemContainerGenerator.ContainerFromItem(itemData) as UIElement;
81+
directlyOverItem = false;
82+
}
83+
}
84+
7585
if (item != null) {
7686
itemParent = ItemsControl.ItemsControlFromItemContainer(item);
7787

GongSolutions.Wpf.DragDrop/Utilities/ItemsControlExtensions.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,18 @@ public static class ItemsControlExtensions
2020
{
2121
public static CollectionViewGroup FindGroup(this ItemsControl itemsControl, Point position)
2222
{
23-
var element = itemsControl.InputHitTest(position) as DependencyObject;
23+
if (itemsControl.Items.Groups == null || itemsControl.Items.Groups.Count == 0)
24+
{
25+
return null;
26+
}
2427

25-
if (element != null) {
28+
var element = itemsControl.InputHitTest(position) as DependencyObject;
29+
if (element != null)
30+
{
2631
var groupItem = element.GetVisualAncestor<GroupItem>();
2732

2833
// drag after last item - get group of it
29-
if (itemsControl.Items.Groups != null && groupItem == null && itemsControl.Items.Count > 0)
34+
if (groupItem == null && itemsControl.Items.Count > 0)
3035
{
3136
var lastItem = itemsControl.ItemContainerGenerator.ContainerFromItem(itemsControl.Items.GetItemAt(itemsControl.Items.Count - 1)) as FrameworkElement;
3237
if (lastItem != null)
@@ -45,7 +50,8 @@ public static CollectionViewGroup FindGroup(this ItemsControl itemsControl, Poin
4550
}
4651
}
4752
}
48-
if (groupItem != null) {
53+
if (groupItem != null)
54+
{
4955
return groupItem.Content as CollectionViewGroup;
5056
}
5157
}

0 commit comments

Comments
 (0)