/// <summary> /// Move item(s). /// </summary> void DragThumb_DragDelta(object sender, DragDeltaEventArgs e) { if (!dragStarted) { if (Math.Abs(e.HorizontalChange) >= MinDistanceToStart || Math.Abs(e.VerticalChange) >= MinDistanceToStart) { Start(); dragStarted = true; } } if (dragStarted) { if (diagramDesignerVM == null) { return; } // update position of the drag adorner DiagramItemsMovementInfo movementInfo = diagramDesignerVM.CalcMovementInfo(this.selectedItemsVM, e.HorizontalChange, e.VerticalChange); this.dragAdorner.LeftOffset = movementInfo.HorizontalChange; this.dragAdorner.TopOffset = movementInfo.VerticalChange; } }
/// <summary> /// Dragging has ended, see if VM is IDiagramDesignerItem and notify of moving end. /// </summary> void DragThumb_DragCompleted(object sender, DragCompletedEventArgs e) { if (!dragStarted) { return; } else { dragStarted = false; } DiagramItemsMovementInfo movementInfo = diagramDesignerVM.CalcMovementInfo(this.selectedItemsVM, e.HorizontalChange, e.VerticalChange); diagramDesignerVM.MoveElements(selectedItemsVM, movementInfo); List <DiagramDesignerCanvas> selectionParentCanvases = new List <DiagramDesignerCanvas>(); foreach (DiagramDesignerItem item in selectedItems) { /* * IDiagramItemViewModel designerItem = item.DataContext as IDiagramItemViewModel; * if (designerItem == null) * continue; * * // apply change * double left = designerItem.Left + dragAdorner.LeftOffset; * double top = designerItem.Top + dragAdorner.TopOffset; * designerItem.Location = new PointD(left, top); */ DiagramDesignerCanvas canvas = (item as DiagramDesignerItem).ParentCanvas; if (canvas != null) { if (!selectionParentCanvases.Contains(canvas)) { selectionParentCanvases.Add(canvas); } } } // update diagram surfaces foreach (DiagramDesignerCanvas canvas in selectionParentCanvases) { if (canvas != null) { canvas.InvalidateMeasure(); } } // remove drag adorner if (this.IsMouseCaptured) { this.ReleaseMouseCapture(); } AdornerLayer adornerLayer = AdornerLayer.GetAdornerLayer(this.diagramDesigner); if (adornerLayer != null) { adornerLayer.Remove(this.dragAdorner); } e.Handled = false; }