Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic How to control the position of text in DiagramLink (Read 3159 times)
dev
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 7
Joined: Sep 28th, 2010
How to control the position of text in DiagramLink
Oct 29th, 2010 at 10:53am
Print Post  
I have custom requirement where i need to place the text of connection based on some criteria. How can i get the textblock instance inside the connection
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How to control the position of text in Diagram
Reply #1 - Oct 29th, 2010 at 1:58pm
Print Post  
There are TextBlocks only in the Silverlight control. Here you can use custom drawing:

Code
Select All
private void OnLinkCreated(object sender, LinkEventArgs e)
{
	e.Link.CustomDraw = CustomDraw.Additional;
	e.Link.TextBrush = null;
	e.Link.Text = "test";
}

private void OnDrawLink(object sender, DrawLinkEventArgs e)
{
	e.Graphics.DrawText(new FormattedText(e.Link.Text,
		CultureInfo.CurrentCulture, FlowDirection.LeftToRight,
		new Typeface(e.Link.FontFamily.Source), e.Link.FontSize, Brushes.Black),
		e.Link.Bounds.Location + new Vector(10, 10));
} 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
dev
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 7
Joined: Sep 28th, 2010
Re: How to control the position of text in Diagram
Reply #2 - Nov 2nd, 2010 at 7:35am
Print Post  
When the digramlink is in vertical direction (Top to bottom) the link text is falling on the link. so i need to adjust it to left of the line. In silverlight we used to set the mergin to the textblock.but how can we achive this in wpf control. below is the attachment of the issue

https://doc-0k-2c-docs.googleusercontent.com/docs/secure/a5hp7cd24hvad7p0p893luk...

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How to control the position of text in Diagram
Reply #3 - Nov 2nd, 2010 at 8:22am
Print Post  
The image link is broken, but I suppose it should look like this:

Code
Select All
private void OnDrawLink(object sender, DrawLinkEventArgs e)
{
	var link = e.Link;
	var points = link.ControlPoints;
	var origin = points[0];
	var dest = points[points.Count - 1];
	bool vertical = points.Count == 2 && Math.Abs(origin.X - dest.X) < 5;
	if (vertical)
	{
		double textWidth = diagram.MeasureString(link.Text, link, 1000).Width;
		e.Graphics.DrawText(new FormattedText(link.Text,
			CultureInfo.CurrentCulture, FlowDirection.LeftToRight,
			new Typeface(link.FontFamily.Source), link.FontSize, Brushes.Black),
			new Point(origin.X - textWidth - 10, (origin.Y + dest.Y - link.FontSize) / 2));
	}
	else
	{
		...
	}
} 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint