/// <summary> /// Handels all necessary steps to start dragging /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void StartDragging(object sender, MouseButtonEventArgs e) { MouseHelper.TrapMouseInsideControl(editorBorder); _selectedComponent = (WorkflowComponentUserControl)sender; if (e.OriginalSource is Ellipse) { var component = _selectedComponent.Component; _customPath = new CustomPath(component, new Point(component.X + 95, component.Y + ComponentHeight / 2 - ComponentPadding)); editorCanvas.Children.Add(_customPath.Path); MouseMove += MovePath; WorkflowComponentUserControls.ForEach(comp => comp.NewSource(_selectedComponent.Component)); } else { _startPoint = e.GetPosition(_selectedComponent); MouseMove += MoveComponent; } }
/// <summary> /// Draws all connections between components of this workflow /// </summary> private void DrawConnections() { foreach (var item in Workflow.Components) { var source = new Point(item.X + 95, item.Y + ComponentHeight / 2 - ComponentPadding); foreach (var id in item.ConnectedTo) { WorkflowComponent nextComponent = Workflow.GetNext(id); Point destination = new Point(nextComponent.X + ComponentPadding - 5, nextComponent.Y + ComponentHeight / 2 - ComponentPadding); var path = new CustomPath(item, source, destination) { Destination = nextComponent }; path.Path.MouseLeftButtonDown += DeleteConnection; editorCanvas.Children.Add(path.Path); _myLines.Add(path); } } }
/// <summary> /// Finishes the drag and drop action /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void FinishMoving(object sender, MouseButtonEventArgs e) { MouseHelper.ClearMouseTrap(); if (_selectedComponent != null) { _startPoint = new Point(); MouseMove -= MoveComponent; _selectedComponent = null; } if (_customPath != null) { MouseMove -= MovePath; editorCanvas.Children.Remove(_customPath.Path); if (CurrentHoveredComponent != null) { AddConnection(_customPath.Source, (CurrentHoveredComponent as WorkflowComponentUserControl).Component); } _customPath = null; DrawCanvas(this, null); } }