public static void OnMouseDown(TreeViewItemEx tvItem, MouseButtonEventArgs e) { if (e.ButtonState == MouseButtonState.Pressed && (e.ChangedButton == MouseButton.Left || e.ChangedButton == MouseButton.Right)) { dragInfo = new DragInfo(tvItem, e); } }
public static void OnMouseMove(TreeViewEx treeView, MouseEventArgs e) { if (dragInfo == null) { return; } if (dragInfo.ShouldCancel(e)) { dragInfo = null; } else if (dragInfo.SouldStartDrag(e)) { dragInfo.GatherSelectedItems(treeView); if (dragInfo.CanStartDrag()) { var dataObject = DataObjectGenerator.Genrate(dragInfo.SourceItems, includeObject: true); if (dragInfo.DirectVisualSourceItem.Item.IsInEditMode) { dragInfo.DirectVisualSourceItem.Item.CommitEdit(); } try { System.Diagnostics.Debug.WriteLine($"StartDrag: {dragInfo.DirectVisualSourceItem.Item}"); dragInfo.IsDragInProgress = true; var result = System.Windows.DragDrop.DoDragDrop(treeView, dataObject, DragDropEffects.Move | DragDropEffects.Copy); dragInfo.IsDragInProgress = false; if (result != DragDropEffects.None) { HandleDropForSource(result); } } finally { Cancel(); } } } }
private static void Cancel() { dropInfo?.DropTargetAdorner?.Detach(); dropInfo = null; dragInfo = null; }