New to Telerik UI for WPF? Download free 30-day trial

Prevent RadDiagramConnection Point from Delete

Environment

Product Version 2019.3.1023
Product RadDiagram for WPF

Description

How to prevent RadDiagramConnection point from delete.

Solution

To achieve this requirement you can handle the PreviewMouseLeftButtonDown event of RadDiagram in the situation when Ctrl is pressed and a RadDiagramConnection point is under the mouse.

Example 1: Prevent RadDiagramConnection Point from Delete

    private void Diagram_PreviewMouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e) 
    { 
        var selectionService = this.diagram.ServiceLocator.GetService<ISelectionService<IDiagramItem>>() as SelectionService; 
        if (KeyboardModifiers.IsControlDown) 
        { 
            var selectedConnection = selectionService.SelectedConnections.FirstOrDefault(); 
            if (selectedConnection != null) 
            { 
                var position = e.GetPosition(this.diagram); 
                var transformedPosition = this.diagram.GetTransformedPoint(position); 
                var relativePoint = new Point(transformedPosition.X - 5, transformedPosition.Y - 5); 
                var rect = new Rect(relativePoint, new Size(10, 10)); 
                if (connection.ConnectionPoints.Any(rect.Contains)) 
                { 
                    e.Handled = true; 
                } 
            } 
        } 
    } 
In this article