Hi,
There is no built-in support for aligning nodes by their geometries. You will have to implement that yourself, by overriding either UpdateModify in a custom node type, or AlignPointToGrid in a derived Diagram class. For example, this aligns the dragged node's top-middle point to a target node's interior point (X at center, Y at 2/3 height):
protected override void UpdateModify(Point current, InteractionState ist)
{
base.UpdateModify(current, ist);
Align(current, ist);
}
protected override void CompleteModify(Point end, InteractionState ist)
{
base.CompleteModify(end, ist);
Align(end, ist);
}
private void Align(Point current, InteractionState ist)
{
if (ist.AdjustmentHandle == 8 /* move */)
{
var nearbyNode = Parent.GetNearestNode(current, 60, this);
if (nearbyNode != null)
{
var r1 = nearbyNode.Bounds;
var targetPoint = new Point(r1.X + r1.Width / 2, r1.Bottom - r1.Height / 3);
var r2 = this.Bounds;
var pointToSnap = new Point(r2.X + r2.Width / 2, r2.Y);
double dx = targetPoint.X - pointToSnap.X;
double dy = targetPoint.Y - pointToSnap.Y;
r2.Offset(dx, dy);
SetBounds(r2, true, true);
}
}
}
If you use only a few node types, your could keep potential pointToSnap / targetPoint lists for each pair of node types. Otherwise you could loop over points of both nodes' geometries, in sequences of 3, and check whether the current 3 points of the dragged node are at the same offset from the current 3 points of the target node; in such case, use the middle points of the sequences as snap / target points.
I hope that helps,
Stoyan