This is a migrated thread and some comments may be shown as answers.

Custom Connectors Tool Error When Zoom the Diagram

2 Answers 88 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
Li
Top achievements
Rank 1
Li asked on 14 May 2020, 10:40 AM
Hi ,I'm Using The sample of  Custom Connectors Tools, But after I zoom the Diagram,and  Then I use Control+Shift+mouse click to add a custom connector ,It can not add a Correct Connector on the shape, Where should I modify the code?Thanks

2 Answers, 1 is accepted

Sort by
0
Dinko | Tech Support Engineer
Telerik team
answered on 19 May 2020, 06:50 AM

Hello Li,

Thank you for your interest in our RadDiagram control for WPF.

To calculate the correct position when the diagram is zoom, you need to use the GetTransformedPoint() method of the RadDiagram. You can check the modified version of the MouseDown event handler from the mentioned example in your post.

public bool MouseDown(PointerArgs e)
{          
    this.areCtrlShiftDown = (Keyboard.Modifiers & ModifierKeys.Shift) == ModifierKeys.Shift &&
                            (Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control;
    if (this.areCtrlShiftDown)
    {
        Point transformedPoint = Diagram.GetTransformedPoint(Mouse.GetPosition(Diagram));
        RadDiagramShape topShape = this.HitService.GetTopItemNearPoint(transformedPoint, 0) as RadDiagramShape;
        if (topShape != null)
        {
            var zoomLevel = this.diagram.Zoom;
                    
            RadDiagramConnector connector = new RadDiagramConnector() { }; 
            connector.Name = "NewConnector" + connector.GetHashCode().ToString();

            double xRatio = (transformedPoint.X - topShape.Bounds.X) / topShape.Width;
            double yRatio = (transformedPoint.Y - topShape.Bounds.Y) / topShape.Height;

            connector.Offset = new Point(xRatio, yRatio);
            topShape.Connectors.Add(connector);

            this.lastUsedShape = topShape;
            return true;
        }
    }
    return false;
}

Regards,
Dinko
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
0
Li
Top achievements
Rank 1
answered on 22 May 2020, 10:00 AM
It works! Thanks a lot Dinko~Have a nice day
Tags
Diagram
Asked by
Li
Top achievements
Rank 1
Answers by
Dinko | Tech Support Engineer
Telerik team
Li
Top achievements
Rank 1
Share this question
or