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

Connection Attachment Behaviour

2 Answers 175 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
Ben
Top achievements
Rank 1
Ben asked on 27 Jun 2017, 08:01 AM

Hi,

We're using RadDiagram in our application and are trying to use the connector tool to connect two shapes. The shapes have the default connector position ('Auto'), leaving an attachment in the centre of the shape, and we have gliding connectors enabled.

How does the connector attachment behaviour work in RadDiagram? Presumably there's some maximum distance from the target connector that the mouse must be before a connector's IsActive is set to true?

We're finding that, to successfully connect the shapes, we must click, drag and then hold directly over the connector to get the connection to attach properly. What we'd like is to be able to drag the connection anywhere on the shape and it automatically attach to the connector, so long as the connection is dropped on the shape.

Regards,

Ben

2 Answers, 1 is accepted

Sort by
0
Petar Mladenov
Telerik team
answered on 29 Jun 2017, 11:42 AM
Hello Ben,

The connectors are activated when minimum distance is reached. This is controlled by the DiagramConstants.ConnectorActivationRadius. However, gliding connectors are something virtual and they are not something visual which resides in control template - attaching to gliding connector pretty much like attaching to Auto connector. To achieve your goal you can subscribe to ConnectionManipulationCompleted event like so:

IHitTestService hitService;
        public Example()
        {
            InitializeComponent();
            this.xDiagram.ConnectionManipulationCompleted += this.xDiagram_ConnectionManipulationCompleted;
            this.hitService = this.xDiagram.ServiceLocator.GetService<IHitTestService>();
        }
 
        private void xDiagram_ConnectionManipulationCompleted(object sender, Telerik.Windows.Controls.Diagrams.ManipulationRoutedEventArgs e)
        {
            if (e.ManipulationStatus == ManipulationStatus.Moved)
            {
                if (this.hitService != null)
                {
                    RadDiagramShape shape = this.hitService.GetTopShapesUnderPoint(e.CurrentPosition).FirstOrDefault() as RadDiagramShape;
                    if (shape != null && shape.UseGlidingConnector)
                    {
                        Dispatcher.BeginInvoke(new Action(() => { e.Connection.Target = shape; }));
                    }
                }
            }
        }

Other way around which requires lot of code (but is more flexible) is to create custom connection tool. For this purpose, you can take a look at the following sample:

Diagram Custom Connection Tool SDK

Regards,
Petar Mladenov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Ben
Top achievements
Rank 1
answered on 29 Jun 2017, 03:51 PM

Hi Petar,

That's great- we went with the hit test service solution and it is working in our application.

Many thanks,

Ben

Tags
Diagram
Asked by
Ben
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
Ben
Top achievements
Rank 1
Share this question
or