Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Do you have a custom link example? (Read 2388 times)
chowy
Junior Member
**
Offline


I Love MindFusion!

Posts: 72
Joined: May 8th, 2017
Do you have a custom link example?
Jun 29th, 2017 at 2:46am
Print Post  
Do you have a custom link example? I want to create my own link class, inherited from diagramlink. And, I want to set the link only to connect to the anchor point. I found the installation package demo, almost no examples of custom link. I want to learn more about this link. Grin
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Online


tech.support

Posts: 3147
Joined: Oct 19th, 2005
Re: Do you have a custom link example?
Reply #1 - Jun 29th, 2017 at 6:23am
Print Post  
Try this -

Code
Select All
class MyLink : DiagramLink
{
	public MyLink(Diagram parent) : base(parent)
	{
		MyProperty = "go there";
	}

	public override void Draw(
		System.Windows.Media.DrawingContext graphics,
		MindFusion.Diagramming.Wpf.RenderOptions options)
	{
		base.Draw(graphics, options);
		var width = Parent.MeasureString(MyProperty, this, 1000).Width + 10;
		var bounds = new Rect(
			EndPoint, new Size(width, 100));
		if (EndPoint.X > StartPoint.X)
			bounds.Offset(-bounds.Width, 0);
		bounds.Offset(-Bounds.X, -Bounds.Y);
		Parent.DrawStyledText(graphics, MyProperty, this, bounds);
	}

	protected override void SaveToXml(XmlElement xmlElement, XmlPersistContext context)
	{
		base.SaveToXml(xmlElement, context);
		context.WriteString(MyProperty, "MyProperty", xmlElement);
	}

	protected override void LoadFromXml(XmlElement xmlElement, XmlPersistContext context)
	{
		base.LoadFromXml(xmlElement, context);
		MyProperty = context.ReadString("MyProperty", xmlElement);
	}

	public string MyProperty { get; set; }
}

public partial class MainWindow : Window
{
	public MainWindow()
	{
		InitializeComponent();

		Diagram.RegisterItemClass(typeof(MyLink), "my:MyLink", 100);

		diagram.Behavior = Behavior.Custom;
		diagram.CustomLinkType = typeof(MyLink);

		diagram.AllowUnanchoredLinks = false;
		diagram.SnapToAnchor = SnapToAnchor.OnCreateOrModify;
		.....
 



Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
chowy
Junior Member
**
Offline


I Love MindFusion!

Posts: 72
Joined: May 8th, 2017
Re: Do you have a custom link example?
Reply #2 - Jun 29th, 2017 at 8:26am
Print Post  
Slavcho wrote on Jun 29th, 2017 at 6:23am:
Try this -

Code
Select All
class MyLink : DiagramLink
{
	public MyLink(Diagram parent) : base(parent)
	{
		MyProperty = "go there";
	}

	public override void Draw(
		System.Windows.Media.DrawingContext graphics,
		MindFusion.Diagramming.Wpf.RenderOptions options)
	{
		base.Draw(graphics, options);
		var width = Parent.MeasureString(MyProperty, this, 1000).Width + 10;
		var bounds = new Rect(
			EndPoint, new Size(width, 100));
		if (EndPoint.X > StartPoint.X)
			bounds.Offset(-bounds.Width, 0);
		bounds.Offset(-Bounds.X, -Bounds.Y);
		Parent.DrawStyledText(graphics, MyProperty, this, bounds);
	}

	protected override void SaveToXml(XmlElement xmlElement, XmlPersistContext context)
	{
		base.SaveToXml(xmlElement, context);
		context.WriteString(MyProperty, "MyProperty", xmlElement);
	}

	protected override void LoadFromXml(XmlElement xmlElement, XmlPersistContext context)
	{
		base.LoadFromXml(xmlElement, context);
		MyProperty = context.ReadString("MyProperty", xmlElement);
	}

	public string MyProperty { get; set; }
}

public partial class MainWindow : Window
{
	public MainWindow()
	{
		InitializeComponent();

		Diagram.RegisterItemClass(typeof(MyLink), "my:MyLink", 100);

		diagram.Behavior = Behavior.Custom;
		diagram.CustomLinkType = typeof(MyLink);

		diagram.AllowUnanchoredLinks = false;
		diagram.SnapToAnchor = SnapToAnchor.OnCreateOrModify;
		.....
 



Regards,
Slavcho
Mindfusion


By the way, I would like to ask about printing. Can WPF versions support printing by region? Like winform fit fit to page and switch horizontal or portrait.Thanks!!
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Online


tech.support

Posts: 3147
Joined: Oct 19th, 2005
Re: Do you have a custom link example?
Reply #3 - Jun 29th, 2017 at 9:04am
Print Post  
It's only available in WinForms version out of the box at this time. For WPF one you can implement landscape and custom page sizes as shown here -
http://mindfusion.eu/Forum/YaBB.pl?num=1261177195/4#4

Setting PrintOptions.Scale to something like 100 * page size / diagram size should let you fit inside a page.

Regards,
Slavcho
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint