How to prevent moving connection / link / line

2 posts, 0 answers
  1. Daniel
    Daniel avatar
    4 posts
    Member since:
    Aug 2015

    Posted 04 Mar 2016 Link to this post


    On my RadDiagram control I have generated elements with connections. How to prevent moving connection?
    I want to allow the user only to detach and attach the connection. Forbidden situation is visualised in forbiddenSituation.PNG.  If the user unpin the connection and he/she doesn't drag connection to another item, the connection shouldn't be changed. So all connections should have Target and Source element.

    I use ConnectionManipulationCompleted event. When ManipulationStatus is Moved I want to Undo this, but the truth is only the previous change will be undone, not current connection moving.

    I was thinking I can cache previous state of connection (target and source) on ConnectionManipulationStared and set those if on ConnectionManipulationCompleted target or source are null. But it doesn't work.
  2. Martin Ivanov
    Martin Ivanov avatar
    1442 posts

    Posted 07 Mar 2016 Link to this post

    Hi Daniel,

    In order to achieve your requirement you can save the connection target and source shapes in the ConnectionManipulationStarted event handler and then reset them in the ConnectionManipulationCompleted handler. Here is an example in code:
    public partial class MainWindow : Window
        private IShape connectionSource;
        private IShape connectionTarget;       
        public MainWindow()
            this.diagram.ConnectionManipulationStarted += diagram_ConnectionManipulationStarted;
            this.diagram.ConnectionManipulationCompleted += diagram_ConnectionManipulationCompleted;
        void diagram_ConnectionManipulationStarted(object sender, ManipulationRoutedEventArgs e)
            this.connectionSource = e.Connection.Source;
            this.connectionTarget = e.Connection.Target;
        void diagram_ConnectionManipulationCompleted(object sender, ManipulationRoutedEventArgs e)
            if (e.ManipulationStatus != ManipulationStatus.Attaching)
               Dispatcher.BeginInvoke(new Action(() => {                   
                    e.Connection.Source = this.connectionSource;
                    e.Connection.Target = this.connectionTarget;                   
                    this.connectionSource = null;
                    this.connectionTarget = null;
    As I understand you want to move the connection only if its reattached to a shape. In this case you can check for the ManipulationStatus.Attaching as demonstrated in the code snippet. Keep in mind that you will need to slightly delay the connection reattaching, otherwise it is too early for setting a new source and target. This is why there is a Dispatcher used in the code snippet above.

    Please try this approach and let me know if it works for you.

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top