Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Text on link base and head (Read 2597 times)
binuvc
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 46
Joined: Nov 7th, 2011
Text on link base and head
Jan 24th, 2012 at 8:08am
Print Post  
Hi,

   Is there any way we can place text near the link base and link head?

   The Text property of the link is already being used for displaying some other information.

   Please advice

Thanks
BinuVC
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Text on link base and head
Reply #1 - Jan 25th, 2012 at 9:33am
Print Post  
Hi,

You will have to derive from DiagramLink to add new text properties:

Code
Select All
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:

Code
Select All
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
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint