/// <summary> /// New drop target identified /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void PreviewDragEnter(object sender, DragEventArgs e) { e.Handled = true; e.Effects = DragDropEffects.None; var itemsControl = (ItemsControl)sender; // Do not allow if sorted. if (!DragUtilities.CanReorderCollectionView(itemsControl)) { return; } if (e.Data.GetDataPresent(this.ItemTypeKey)) { DragInfo data = e.Data.GetData(this.ItemTypeKey) as DragInfo; if (data != null) { if (!data.AllowOnlySelf || itemsControl == data.Source) { var allowedEffects = e.AllowedEffects; if (itemsControl == data.Source && !this.AllowSelf) { allowedEffects = DragDropEffects.None; } else if (this.DropEnter != null) { DragDropEventArgs de = new DragDropEventArgs(data.Source, itemsControl, data.Data) { AllowedEffects = allowedEffects }; this.DropEnter(this, de); allowedEffects = de.AllowedEffects; if (de.Cancel) { return; } } this.InitializeDragAdorner(itemsControl, data.Data, e.GetPosition(itemsControl)); e.Effects = GetDropEffectType(allowedEffects, e.KeyStates); if (e.Effects != DragDropEffects.None) { this.InitializeInsertAdorner(itemsControl, e); } } } } }
/// <summary> /// Display the drag indicator /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void PreviewMouseMove(object sender, MouseEventArgs e) { if (this._isMouseDown) { var itemsControl = (ItemsControl)sender; Point currentPosition = e.GetPosition(itemsControl); if ((this._isDragging == false) && (Math.Abs(currentPosition.X - this._dragStartPosition.X) > SystemParameters.MinimumHorizontalDragDistance) || (Math.Abs(currentPosition.Y - this._dragStartPosition.Y) > SystemParameters.MinimumVerticalDragDistance)) { // Do not allow if sorted and we only allow this element as // the drop target. if (!DragUtilities.CanReorderCollectionView(itemsControl) && this.AllowOnlySelf) { return; } this.DragStarted(itemsControl); } } }