void OnDrop(object sender, DragEventArgs e) { if (this.isDragging && e.Data.GetDataPresent(formatName)) { object dragSource = e.Data.GetData(formatName); if (dragSource != null) { DragDropTarget dropTarget = this.calledBackForValidatingTarget(dragSource, e.OriginalSource, e.Effects); if (dropTarget != null) { if (dragSource != dropTarget.DataSource) { e.Handled = true; UpdateEffects(e); DestroyDragDropWindow(); this.calledBackFinalDropOperation(dragSource, dropTarget.DataSource, e.Effects); } } } } DragDropRemoveAnyAdorner(); }
private bool UpdateEffects(DragEventArgs e) { if (!this.isDragging) { DragDropRemoveAnyAdorner(); e.Effects = DragDropEffects.None; return(true); } object dragSource = e.Data.GetData(formatName); if (dragSource == null) { DragDropRemoveAnyAdorner(); e.Effects = DragDropEffects.None; return(false); } const int dragScrollMarginSpeedSlow = 30; const int dragScrollMarginFast = 10; Point pt = e.GetPosition(this.mainControl); HitTestResult result = VisualTreeHelper.HitTest(this.mainControl, pt); if (result != null) { if (pt.Y < dragScrollMarginSpeedSlow) { // The user is close to the bottom of the container (ListBox or TreeView) if (pt.Y < dragScrollMarginFast) { AttemptToScrollUp(4); } else { AttemptToScrollUp(1); } } else if (pt.Y > this.mainControl.ActualHeight - dragScrollMarginSpeedSlow) { // The user is close to the bottom of the container (ListBox or TreeView) if (pt.Y > this.mainControl.ActualHeight - dragScrollMarginFast) { AttemptToScrollDown(4); } else { AttemptToScrollDown(1); } } FrameworkElement ctrl = result.VisualHit as FrameworkElement; if (ctrl != null) { DragDropTarget possibleDropTarget = this.calledBackForValidatingTarget(dragSource, ctrl, e.Effects); if (possibleDropTarget != null && possibleDropTarget.DataSource != previousPossibleDropTarget) { if (possibleDropTarget.DataSource != dragSource) { DragDropRemoveAnyAdorner(); previousPossibleDropTarget = possibleDropTarget.DataSource; this.adornerLayer = AdornerLayer.GetAdornerLayer(possibleDropTarget.TargetElement); lastAdornerUsed = new AdornerDropTarget(possibleDropTarget.TargetElement); this.adornerLayer.Add(lastAdornerUsed); } } } else { DragDropRemoveAnyAdorner(); } } else { DragDropRemoveAnyAdorner(); } if (((e.AllowedEffects & DragDropEffects.Copy) == DragDropEffects.Copy) || ((e.AllowedEffects & DragDropEffects.Move) == DragDropEffects.Move)) { if ((e.KeyStates & DragDropKeyStates.ControlKey) == DragDropKeyStates.ControlKey) { e.Effects = DragDropEffects.Copy; } else { e.Effects = DragDropEffects.Move; } if (e.Effects != currentEffect) { currentEffect = e.Effects; } } else { e.Effects = e.AllowedEffects & ((DragDropEffects.Copy | DragDropEffects.Move) ^ (DragDropEffects.All)); } return(true); }