private void TreeViewExplorer_Drop(object sender, DragEventArgs e) { if (e.Data.GetDataPresent(typeof(ClipboardBufferData))) { ClipboardBufferData data = e.Data.GetData(typeof(ClipboardBufferData)) as ClipboardBufferData; Point currentPosition = e.GetPosition(TreeViewExplorer); TreeViewItem item = TreeViewExtensions.GetNearestContainer(e.OriginalSource as UIElement); //Можно ли вставить данные сюда? if (item == null) { return; } var elem = item.Tag as ProjectElementBase; if (elem == null) { return; } if (elem is IDropable) { (elem as IDropable).Drop(data); } } }
private void TreeViewExplorer_DragOver(object sender, DragEventArgs e) { try { Point currentPosition = e.GetPosition(TreeViewExplorer); if ((Math.Abs(currentPosition.X - startPoint.X) > SystemParameters.MinimumHorizontalDragDistance) || (Math.Abs(currentPosition.Y - startPoint.Y) > SystemParameters.MinimumVerticalDragDistance)) { // Verify that this is a valid drop and then store the drop target TreeViewItem item = TreeViewExtensions.GetNearestContainer(e.OriginalSource as UIElement); //Можно ли вставить данные сюда? var elem = item.Tag as ProjectElementBase; ClipboardBufferData data = e.Data.GetData(typeof(ClipboardBufferData)) as ClipboardBufferData; e.Effects = ((elem is IDropable) && ((elem as IDropable).CanDrop(data))) ? DragDropEffects.Move : DragDropEffects.None; e.Handled = true; return; } e.Effects = DragDropEffects.None; e.Handled = true; return; } catch (Exception) { } }
private void TreeViewExplorer_MouseMove(object sender, MouseEventArgs e) { TreeViewItem item = TreeViewExtensions.GetNearestContainer(e.OriginalSource as UIElement); if ((e.LeftButton == MouseButtonState.Pressed) && (item != null)) { var mousePos = e.GetPosition(null); var diff = startPoint - mousePos; if (Math.Abs(diff.X) > SystemParameters.MinimumHorizontalDragDistance || Math.Abs(diff.Y) > SystemParameters.MinimumVerticalDragDistance) { if (selectedItems.Count != 0) { List <ProjectElementBase> elements = new List <ProjectElementBase>(); foreach (TreeViewItem i in selectedItems) { if (i != null) { ProjectElementBase elem = i.Tag as ProjectElementBase; elements.Add(elem); } } if (ClipboardBufferData.CheckGroupValid(elements) != GroupType.IllegalGroup) { var dragData = new DataObject(new ClipboardBufferData(ClipboardOperationType.Cut, elements)); DragDrop.DoDragDrop(TreeViewExplorer, dragData, DragDropEffects.Move | DragDropEffects.None); } } } } }