Skip to content

Commit

Permalink
Merge pull request #122 from sm-g/drag-after-last-item-grouped
Browse files Browse the repository at this point in the history
Support drag after last item in grouped list
  • Loading branch information
punker76 committed Jan 21, 2015
2 parents 669e50c + 9f28fec commit 1b0671b
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 1b0671b

Please sign in to comment.