/// <summary> /// Handles the PreviewDrop event of a DropTarget ItemsControl /// </summary> private void DropTarget_PreviewDrop(object sender, DragEventArgs e) { object draggedItem = e.Data.GetData(this.format.Name); int indexRemoved = -1; if (draggedItem != null) { if (this.sourceItemsControl != null) { if ((e.Effects & DragDropEffects.Move) != 0) { indexRemoved = DragDropUtilities.RemoveItemFromItemsControl(this.sourceItemsControl, draggedItem); } // This happens when we drag an item to a later position within the same ItemsControl. if (indexRemoved != -1 && this.sourceItemsControl == this.targetItemsControl && indexRemoved < this.insertionIndex) { this.insertionIndex--; } } DragDropUtilities.InsertItemInItemsControl(this.targetItemsControl, draggedItem, this.insertionIndex); RemoveDraggedAdorner(); if (GetIsInsertionAdornerEnabled(sender as Visual)) { RemoveInsertionAdorner(); } var element = sender as FrameworkElement; if (element != null) { var args = new OnDropEventArgs(OnDropEvent, e, draggedItem); element.RaiseEvent(args); } } e.Handled = true; }
/// <summary> /// Handles the PreviewDrop event of a DropTarget ItemsControl /// </summary> private void DropTarget_PreviewDrop(object sender, DragEventArgs e) { object draggedItem = e.Data.GetData(this.format.Name); int indexRemoved = -1; if (draggedItem != null) { if (this.sourceItemsControl != null) { if ((e.Effects & DragDropEffects.Move) != 0) { indexRemoved = DragDropUtilities.RemoveItemFromItemsControl(this.sourceItemsControl, draggedItem); } // This happens when we drag an item to a later position within the same ItemsControl. if (indexRemoved != -1 && this.sourceItemsControl == this.targetItemsControl && indexRemoved < this.insertionIndex) { this.insertionIndex--; } } DragDropUtilities.InsertItemInItemsControl(this.targetItemsControl, draggedItem, this.insertionIndex); RemoveDraggedAdorner(); if (GetIsInsertionAdornerEnabled(sender as Visual)) RemoveInsertionAdorner(); var element = sender as FrameworkElement; if (element != null) { var args = new OnDropEventArgs(OnDropEvent, e, draggedItem); element.RaiseEvent(args); } } e.Handled = true; }