I am not assign links programmatically. I create a node by clicking on button:
private void Button_Click_1(object sender, RoutedEventArgs e)
{
AddElemWnd dlg = new AddElemWnd();
if ((bool)dlg.ShowDialog())
{
uint nInpNum = uint.Parse(dlg.textBoxInps.Text);
uint nOutNum = uint.Parse(dlg.textBoxOuts.Text);
ShapeNode node = m_Diagram.Factory.CreateShapeNode(40, 40, 8, 180, Shapes.Rectangle);
AnchorPointCollection anchorPnts = new AnchorPointCollection();
double nOffset = nInpNum > 0 ? 100 / (nInpNum + 1) : 50;
for (int i = 0; i < nInpNum; ++i)
{
AnchorPoint point = new AnchorPoint(0,
nOffset * (i + 1), true, false, MarkStyle.Rectangle);
anchorPnts.Add(point);
}
nOffset = nOutNum > 0 ? 100 / (nOutNum + 1) : 50;
for (int i = 0; i < nOutNum; ++i)
{
AnchorPoint point = new AnchorPoint(100,
nOffset * (i + 1), false, true, MarkStyle.Rectangle);
anchorPnts.Add(point);
}
node.AnchorPattern = new AnchorPattern(anchorPnts);
node.EnabledHandles = AdjustmentHandles.ResizeTopCenter |
AdjustmentHandles.ResizeBottomCenter | AdjustmentHandles.Move;
node.HandlesStyle = HandlesStyle.EasyMove;
node.Brush = Brushes.Black;
NodeProperties props = new NodeProperties(nInpNum, nOutNum);
node.Tag = props;
}
}
After that I call an item of context menu of the diagram to change count of AnchorPoints such as:
private void Button_Click_2(object sender, RoutedEventArgs e)
{
AddElemWnd dlg = new AddElemWnd();
if ((bool)dlg.ShowDialog())
{
uint nInpNum = uint.Parse(dlg.textBoxInps.Text);
uint nOutNum = uint.Parse(dlg.textBoxOuts.Text);
DiagramItem item = m_Diagram.ActiveItem;
if (item == null || item.GetType() != typeof(ShapeNode)) return;
ShapeNode node = (ShapeNode)m_Diagram.ActiveItem;
if (node.Tag == null || node.Tag.GetType() != typeof(NodeProperties)) return;
AnchorPattern ap = node.AnchorPattern;
AnchorPointCollection anchorPnts = ap.Points;
NodeProperties props = (NodeProperties)node.Tag;
if (props.IncommingPointCount > nInpNum)
{
int i = 0, nFoundIncomming = 0;
while (i < anchorPnts.Count)
{
if (anchorPnts[i].AllowIncoming)
{
nFoundIncomming++;
if (nFoundIncomming > nInpNum)
{
anchorPnts.RemoveAt(i);
nFoundIncomming--;
continue;
}
}
i++;
}
props.IncommingPointCount = nInpNum;
}
if (props.OutgoingPointCount > nOutNum)
{
int i = 0, nFoundOutgoing = 0;
while (i < anchorPnts.Count)
{
if (anchorPnts[i].AllowOutgoing)
{
nFoundOutgoing++;
if (nFoundOutgoing > nOutNum)
{
anchorPnts.RemoveAt(i);
nFoundOutgoing--;
continue;
}
}
i++;
}
}
double fOffset = nInpNum > 0 ? 100 / (nInpNum + 1) : 50;
double fOffset2 = nOutNum > 0 ? 100 / (nOutNum + 1) : 50;
node.AnchorPattern = ap;
node.Repaint(true);
}
}
So, in that time I don't have any assigned links, but when the mouse is over I want to see the new count of points. In this example of code I realized the situation when I want to decrease the count of incomming and outgoing AnchorPoints. So to test this code it is necessary to create for example 10 incomming points and 8 outgoing points. And after that try to change them to 5 and 3 accordingly