Hi,
You will have to derive from DiagramLink to add new text properties:
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows.Shapes;
using MindFusion.Diagramming.Silverlight;
namespace Test
{
public class MyLink : DiagramLink
{
public MyLink(Diagram diagram) : base(diagram)
{
}
public MyLink(Diagram d, DiagramNode origin, Point point) :
base(d, origin, point)
{
}
protected override void UpdateVisuals()
{
base.UpdateVisuals();
var canvas = Content as Canvas;
if (canvas != null)
{
if (!canvas.Children.Contains(baseTextBlock))
{
canvas.Children.Add(baseTextBlock);
baseTextBlock.SetBinding(TextBlock.TextProperty,
new Binding("BaseText") { Source = this });
}
const int margin = 5;
var linkBounds = GetBounds();
var points = ControlPoints;
var measure = new TextBlock
{
Text = BaseText, FontFamily = FontFamily, FontSize = FontSize
};
measure.UpdateLayout();
if (points[0].Y > points[1].Y)
{
Canvas.SetTop(baseTextBlock,
points[0].Y - linkBounds.Y - margin - measure.ActualHeight);
}
else
{
Canvas.SetTop(baseTextBlock,
points[0].Y - linkBounds.Y + margin);
}
if (points[0].X > points[1].X)
{
Canvas.SetLeft(baseTextBlock,
points[0].X - linkBounds.X - margin - measure.ActualWidth);
}
else
{
Canvas.SetLeft(baseTextBlock,
points[0].X - linkBounds.X + margin);
}
}
}
static public DependencyProperty BaseTextProperty = DependencyProperty.Register(
"BaseText", typeof(string), typeof(MyLink), new PropertyMetadata("", OnTextChanged));
private static void OnTextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var link = (MyLink)d;
link.UpdateVisuals();
}
public string BaseText
{
get { return (string)GetValue(BaseTextProperty); }
set { SetValue(BaseTextProperty, value); }
}
private readonly TextBlock baseTextBlock = new TextBlock();
}
}
If you let users draw links interactively, you must also create a custom behavior class and assign its instance to diagram.CustomBehavior:
public class MyBehavior : LinkShapesBehavior
{
public MyBehavior(Diagram diagram) : base(diagram) { }
protected override DiagramLink CreateLink(DiagramNode origin, Point point)
{
return new MyLink(Diagram, origin, point);
}
}
I hope that helps,
Stoyan