void AssociatedObject_Drop(object sender, DragEventArgs e) { //if the data type can be dropped if (this.dataType != null) { if (e.Data.GetDataPresent(dataType)) { //first find the UIElement that it was dropped over, then we determine if it's //dropped above or under the UIElement, then insert at the correct index. ItemsControl dropContainer = sender as ItemsControl; //get the UIElement that was dropped over UIElement droppedOverItem = UIHelper.GetUIElement(dropContainer, e.GetPosition(dropContainer)); int dropIndex = -1; //the location where the item will be dropped dropIndex = dropContainer.ItemContainerGenerator.IndexFromContainer(droppedOverItem) + 1; //find if it was dropped above or below the index item so that we can insert //the item in the correct place if (UIHelper.IsPositionAboveElement(droppedOverItem, e.GetPosition(droppedOverItem))) //if above { dropIndex = dropIndex - 1; //we insert at the index above it } //remove the data from the source IDragable source = e.Data.GetData(dataType) as IDragable; source.DroppedItem(e.Data.GetData(dataType)); //drop the data IDropable target = this.AssociatedObject.DataContext as IDropable; target.Drop(e.Data.GetData(dataType), dropIndex); } } if (this.insertAdornerManager != null) { this.insertAdornerManager.Clear(); } e.Handled = true; return; }
void AssociatedObject_Drop(object sender, DragEventArgs e) { if (dataType != null) { //if the data type can be dropped if (e.Data.GetDataPresent(dataType)) { //drop the data IDropable target = this.AssociatedObject.DataContext as IDropable; target.Drop(e.Data.GetData(dataType)); //remove the data from the source IDragable source = e.Data.GetData(dataType) as IDragable; source.DroppedItem(e.Data.GetData(dataType)); } } if (this.adorner != null) { this.adorner.Remove(); } e.Handled = true; return; }