private void MoveNode(double x, double y, Node node, Diagram diagram) { if (diagram.SnapToGrid) { node.X = SnapGrid.Snap(node.X + x, GridSize, GridOffsetLeft); node.Y = SnapGrid.Snap(node.Y + y, GridSize, GridOffsetTop); } else { node.X += x; node.Y += y; } }
private void ItemsControl_Drop(object sender, DragEventArgs e) { if (e.Data.GetDataPresent("ControlTypeFormat")) { string type = e.Data.GetData("ControlTypeFormat") as string; var parent = (ItemsControl)sender; var diagram = this.DataContext as Diagram; Point p = e.GetPosition(parent); if (diagram.SnapToGrid) { p = new Point() { X = SnapGrid.Snap(p.X, GridSize, GridOffsetLeft), Y = SnapGrid.Snap(p.Y, GridSize, GridOffsetTop) }; } DiagramAddDefaultItem(type, diagram, p); } }