Adding conectors programmatically

Coordinator
Jul 1, 2011 at 6:28 AM

[From mail Support] Hi 

I was wondering if there is an example of how to programmatically add a connection between to shapes. I have tries something like this, without much success:

 

  var bc = new Connection();
  bc.Points.Add(new ConnectionPoint()
      {
          ConnectedNode = <some existing node>
      });
  bc.Points.Add(new ConnectionPoint()
  {
      ConnectedNode =  <some existing node>
  });
  Shapes.Add(bc);  //where shapes is bound collection to Diagram

 

Coordinator
Jul 1, 2011 at 6:28 AM

Hi,

you always have to apply a connection between a sink (node and connector) and source (node and connector):

Connection connection = new Connection();
connection.Source.ConnectedNode = src;
connection.Source.ConnectorIndex = srcIndex;
connection.Sink.ConnectedNode = snk;
connection.Sink.ConnectorIndex = snkIndex;

Looks probably  a little bit complicated for you but we decided to use this approach to also have support for defining it in xaml.