Skip to content

Commit

Permalink
support drag after last item in grouped list
Browse files Browse the repository at this point in the history
  • Loading branch information
sm-g committed Jan 19, 2015
1 parent 669e50c commit 9f28fec
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion GongSolutions.Wpf.DragDrop/DropTargetInsertionAdorner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected override void OnRender(DrawingContext drawingContext)
if (targetGroup != null && targetGroup.IsBottomLevel && this.DropInfo.InsertPosition.HasFlag(RelativeInsertPosition.AfterTargetItem)) {
var indexOf = targetGroup.Items.IndexOf(this.DropInfo.TargetItem);
lastItemInGroup = indexOf == targetGroup.ItemCount - 1;
if (lastItemInGroup) {
if (lastItemInGroup && this.DropInfo.InsertIndex != itemParent.Items.Count) {
index--;
}
}
Expand Down
20 changes: 20 additions & 0 deletions GongSolutions.Wpf.DragDrop/Utilities/ItemsControlExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,26 @@ public static CollectionViewGroup FindGroup(this ItemsControl itemsControl, Poin
if (element != null) {
var groupItem = element.GetVisualAncestor<GroupItem>();

// drag after last item - get group of it
if (itemsControl.Items.Groups != null && groupItem == null && itemsControl.Items.Count > 0)
{
var lastItem = itemsControl.ItemContainerGenerator.ContainerFromItem(itemsControl.Items.GetItemAt(itemsControl.Items.Count - 1)) as FrameworkElement;
if (lastItem != null)
{
var itemEndpoint = lastItem.PointToScreen(new Point(lastItem.ActualWidth, lastItem.ActualHeight));
var positionToScreen = itemsControl.PointToScreen(position);
switch (itemsControl.GetItemsPanelOrientation())
{
case Orientation.Horizontal:
// assume LeftToRight
groupItem = itemEndpoint.X <= positionToScreen.X ? lastItem.GetVisualAncestor<GroupItem>() : null;
break;
case Orientation.Vertical:
groupItem = itemEndpoint.Y <= positionToScreen.Y ? lastItem.GetVisualAncestor<GroupItem>() : null;
break;
}
}
}
if (groupItem != null) {
return groupItem.Content as CollectionViewGroup;
}
Expand Down

0 comments on commit 9f28fec

Please sign in to comment.