public EdgeViewModel(ClassBoxViewModel souce, ClassBoxViewModel sink) { edge = new Edge(); sink.connectedEdges.Add(this); souce.connectedEdges.Add(this); Sink = sink.classBox; Source = souce.classBox; }
// There are two reasons for doing a 'MouseUp'. // Either a Line is being drawn, and the second Shape has just been chosen // or a Shape is being moved and the move is now done. // This uses 'var' which is an implicit type variable (https://msdn.microsoft.com/en-us/library/bb383973.aspx). private void MouseUpShape(MouseButtonEventArgs e) { // Used for adding a Line. if (isAddingLine) { // Get source if (addingLineFrom != null) { undoRedoController.AddAndExecute(new AddEdgeCommand(Lines, new EdgeViewModel(addingLineFrom, TargetShape(e)))); addingLineFrom = null; isAddingLine = false; } else { addingLineFrom = TargetShape(e); } } else { // The Shape is gotten from the mouse event. var shape = TargetShape(e); // The mouse position relative to the target of the mouse event. var mousePosition = RelativeMousePosition(e); // The Shape is moved back to its original position, so the offset given to the move command works. shape.X = initialShapePosition.X; shape.Y = initialShapePosition.Y; // Now that the Move Shape operation is over, the Shape is moved to the final position, // by using a MoveNodeCommand to move it. // The MoveNodeCommand is given the offset that it should be moved relative to its original position, // and with respect to the Undo/Redo functionality the Shape has only been moved once, with this Command. undoRedoController.AddAndExecute(new MoveShapeCommand(shape, mousePosition.X - initialMousePosition.X, mousePosition.Y - initialMousePosition.Y)); // The mouse is released, as the move operation is done, so it can be used by other controls. e.MouseDevice.Target.ReleaseMouseCapture(); } }