Thanks Stoyan,
the following code works for me:
private void diagram_ValidateAnchorPoint(object sender, LinkValidationEventArgs e)
{
if (e.Node == MyTableNode)
{
TableNode tn = e.Node as TableNode;
int row = -1;
int column = -1;
if (tn.CellFromPoint(e.MousePosition, true, ref row, ref column))
{
if (tn.Rows[row].AnchorPattern == null)
{
e.Cancel = true;
}
else
{
e.Cancel = AnchorIsOccupied(tn.Rows[row].IncomingLinks, e.AnchorIndex, e.Link);
}
}
else
{
e.Cancel = true;
}
}
else
{
e.Cancel = AnchorIsOccupied(e.Node.IncomingLinks, e.AnchorIndex, e.Link);
}
}
private bool AnchorIsOccupied(DiagramLinkCollection incomingLinks, int anchorIndex, DiagramLink skipThisLink)
{
foreach (DiagramLink link in incomingLinks)
{
if (link == skipThisLink)
{
continue;
}
if (link.DestinationAnchor == anchorIndex)
{
return true;
}
}
return false;
}
The probelm was that there might exists Rows that do not have an AnchorPattern but what they have is an existing Collection of IncomingLink with a count=0.
The only uncomely thing is still that I have to ask for
if(e.Node == MyTableNode)
instead of doing it in inherited manner with virtual methods for TableNode, or TemplatedNode.
Regards and thanks for your patience with me.
Pontius