Hi,
This can be done only by overriding the link's UpdateVisuals method. For example this implements something like the "Distant-Hostile" link:
public class MyLink : DiagramLink
{
public MyLink() {}
public MyLink(Diagram diagram) : base(diagram)
{
}
protected override void UpdateVisuals()
{
base.UpdateVisuals();
var canvas = Content as Canvas;
if (canvas != null)
{
if (!canvas.Children.Contains(myPath))
canvas.Children.Add(myPath);
UpdatePath();
}
}
private void UpdatePath()
{
var b = GetBounds();
var p0 = ControlPoints[0];
p0.X -= b.X; p0.Y -= b.Y;
var p1 = ControlPoints[ControlPoints.Count - 1];
p1.X -= b.X; p1.Y -= b.Y;
double dx = p1.X - p0.X;
double dy = p1.Y - p0.Y;
var g = new PathGeometry();
var f = new PathFigure
{
IsClosed = false,
IsFilled = false,
StartPoint = p0
};
double a = 0, r = 0, s = -1;
CartesianToPolar(p0, p1, ref a, ref r);
for (int i = 1; i < 10; ++i )
{
Point fp = p0;
fp.X += i * dx / 10;
fp.Y += i * dy / 10;
PolarToCartesian(fp, a + s * 90, 20, ref fp);
s *= -1;
f.Segments.Add(new LineSegment { Point = fp });
}
g.Figures.Add(f);
myPath.Data = g;
myPath.Stroke = Brushes.Red;
}
static void PolarToCartesian(Point coordCenter, double a, double r, ref Point cartesian)
{
if (r == 0)
{
cartesian = coordCenter;
return;
}
cartesian.X = coordCenter.X + Math.Cos(a * Math.PI / 180) * r;
cartesian.Y = coordCenter.Y - Math.Sin(a * Math.PI / 180) * r;
}
static void CartesianToPolar(Point coordCenter, Point cartesian, ref double a, ref double r)
{
if (coordCenter == cartesian)
{
a = 0;
r = 0;
return;
}
double dx = cartesian.X - coordCenter.X;
double dy = cartesian.Y - coordCenter.Y;
r = Math.Sqrt(Math.Pow(dx, 2) + Math.Pow(dy, 2));
a = Math.Atan(-dy / dx) * 180 / Math.PI;
if (dx < 0) a += 180;
}
private readonly Path myPath = new Path();
}
You can let users draw that kind of links through a custom Behavior class:
public class MyBehavior : LinkShapesBehavior
{
public MyBehavior(Diagram diagram)
: base(diagram)
{
}
protected override DiagramLink CreateLink(DiagramNode origin, Point point)
{
var link = new MyLink(Diagram);
link.Origin = origin;
return link;
}
}
I hope that helps,
Stoyan