public static void DragSelected(this ISelectionService selectionService, DependencyObject dragSource) { if (selectionService == null) { throw new ArgumentNullException(nameof(selectionService)); } var selected = selectionService.GetSelected(); //Make sure we have something to work with if (selected.Length == 0) { return; } var elements = selected.OfType <IElement>() .ToArray(); //Make sure that these are all elements if (elements.Length != selected.Length) { return; } //Serialize for the clipboard var momento = new ElementClipboardData(elements); //Perform the operation var result = DragDrop.DoDragDrop(dragSource, momento, DragDropEffects.Copy | DragDropEffects.Move); if ((result & DragDropEffects.Move) == DragDropEffects.Move) { //Unselect these - they're going away. selectionService.SelectNone(); //Remove the originals from their spots foreach (var element in elements) { //Remove the element from where it came from element.Parent?.RemoveElement(element); } } }
public static void DragSelected(this ISelectionService selectionService, DependencyObject dragSource) { if (selectionService == null) throw new ArgumentNullException(nameof(selectionService)); var selected = selectionService.GetSelected(); //Make sure we have something to work with if (selected.Length == 0) return; var elements = selected.OfType<IElement>() .ToArray(); //Make sure that these are all elements if (elements.Length != selected.Length) return; //Serialize for the clipboard var momento = new ElementClipboardData(elements); //Perform the operation var result = DragDrop.DoDragDrop(dragSource, momento, DragDropEffects.Copy | DragDropEffects.Move); if ((result & DragDropEffects.Move) == DragDropEffects.Move) { //Unselect these - they're going away. selectionService.SelectNone(); //Remove the originals from their spots foreach (var element in elements) { //Remove the element from where it came from element.Parent?.RemoveElement(element); } } }
private void HandleDrag(DragEventArgs e, bool drop) { this.PerformViewModelAction<FunctionEditorDialogViewModel>(editor => { var data = e.Data.GetData(typeof(ElementClipboardData)) as IElementClipboardData; if (data == null) { var factory = e.Data.GetData(typeof(ElementFactory)) as IElementFactory; if (factory == null) { e.Effects = DragDropEffects.None; return; } //Create data from the factory data = new ElementClipboardData(factory); } //Get the position relative to the design surface var position = e.GetPosition(DesignRoot); //Find the drop target var dropTarget = DesignRoot.GetDropTarget(position, data); //Check to see if we can do this if (dropTarget == null) { if (!editor.Function.CanDrop(data)) { e.Effects = DragDropEffects.None; return; } } else { if (!dropTarget.CanDrop(data)) { e.Effects = DragDropEffects.None; return; } } if (((e.AllowedEffects & DragDropEffects.Move) == DragDropEffects.Move) && ((e.AllowedEffects & DragDropEffects.Copy) == DragDropEffects.Copy) && data.SourceFunctionId.HasValue && data.SourceFunctionId.Value != editor.Function.Id) { e.Effects = DragDropEffects.Copy; } else if ((e.AllowedEffects & DragDropEffects.Move) == DragDropEffects.Move) { e.Effects = DragDropEffects.Move; } else if ((e.AllowedEffects & DragDropEffects.Copy) == DragDropEffects.Copy) { e.Effects = DragDropEffects.Copy; } if (drop) { if (dropTarget == null) { editor.Function.Drop(data, false); } else { dropTarget.Drop(data); } CurrentDropTarget = null; } else { CurrentDropTarget = dropTarget; } e.Handled = true; }); }
private void HandleDrag(DragEventArgs e, bool drop) { this.PerformViewModelAction <FunctionEditorDialogViewModel>(editor => { var data = e.Data.GetData(typeof(ElementClipboardData)) as IElementClipboardData; if (data == null) { var factory = e.Data.GetData(typeof(ElementFactory)) as IElementFactory; if (factory == null) { e.Effects = DragDropEffects.None; return; } //Create data from the factory data = new ElementClipboardData(factory); } //Get the position relative to the design surface var position = e.GetPosition(DesignRoot); //Find the drop target var dropTarget = DesignRoot.GetDropTarget(position, data); //Check to see if we can do this if (dropTarget == null) { if (!editor.Function.CanDrop(data)) { e.Effects = DragDropEffects.None; return; } } else { if (!dropTarget.CanDrop(data)) { e.Effects = DragDropEffects.None; return; } } if (((e.AllowedEffects & DragDropEffects.Move) == DragDropEffects.Move) && ((e.AllowedEffects & DragDropEffects.Copy) == DragDropEffects.Copy) && data.SourceFunctionId.HasValue && data.SourceFunctionId.Value != editor.Function.Id) { e.Effects = DragDropEffects.Copy; } else if ((e.AllowedEffects & DragDropEffects.Move) == DragDropEffects.Move) { e.Effects = DragDropEffects.Move; } else if ((e.AllowedEffects & DragDropEffects.Copy) == DragDropEffects.Copy) { e.Effects = DragDropEffects.Copy; } if (drop) { if (dropTarget == null) { editor.Function.Drop(data, false); } else { dropTarget.Drop(data); } CurrentDropTarget = null; } else { CurrentDropTarget = dropTarget; } e.Handled = true; }); }