protected override void OnPreviewMouseMove(MouseEventArgs e) { base.OnPreviewMouseMove(e); if (!EnableSortByDragAndDrop) { return; } if (_targetContainer?.DataContext == null) { return; } var listBoxItem = _targetContainer as ListBoxItem; if (listBoxItem != null && !listBoxItem.IsSelected) { return; } // 移動量が十分か検証する var currentPosition = PointToScreen(e.GetPosition(_targetContainer)); var delta = (_startPosition - currentPosition); if (!delta.IsEnoughMoveForDrug()) { return; } //Debug.WriteLine("DragDropStart"); _dragAdorner = _dragAdorner ?? (_dragAdorner = DragAdorner.Create(this, _targetContainer, _startPosition)); _dragAdorner.SetOffset(currentPosition.X, currentPosition.Y); DragDrop.DoDragDrop(this, _targetContainer.DataContext, DragDropEffects.Move); // 終わったら後始末 ResetDragAndDropParameter(); }
private void ResetDragAndDropParameter() { //Debug.WriteLine("ResetParameter"); _targetContainer = null; _startPosition = new Point(); _dragAdorner?.Dispose(); _dragAdorner = null; _insertionAdorner?.Dispose(); _insertionAdorner = null; }
protected override void OnPreviewMouseMove(MouseEventArgs e) { base.OnPreviewMouseMove(e); if (!EnableSortByDragAndDrop) return; if (_targetContainer?.DataContext == null) return; var listBoxItem = _targetContainer as ListBoxItem; if (listBoxItem != null && !listBoxItem.IsSelected) return; // 移動量が十分か検証する var currentPosition = PointToScreen(e.GetPosition(_targetContainer)); var delta = (_startPosition - currentPosition); if (!delta.IsEnoughMoveForDrug()) return; //Debug.WriteLine("DragDropStart"); _dragAdorner = _dragAdorner ?? (_dragAdorner = DragAdorner.Create(this, _targetContainer, _startPosition)); _dragAdorner.SetOffset(currentPosition.X, currentPosition.Y); DragDrop.DoDragDrop(this, _targetContainer.DataContext, DragDropEffects.Move); // 終わったら後始末 ResetDragAndDropParameter(); }