Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic How can I get my custom node to size automatically (Read 2310 times)
cds
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 10
Joined: Apr 7th, 2010
How can I get my custom node to size automatically
Apr 21st, 2010 at 3:23am
Print Post  
I am adding custom nodes to my diagram following the tutorial. My custom node is a control with a control template defined in generic.xaml which includeds a TextBlock for some text.

How can I measure the required size with the text set on the TextBlock and then set the node's bounds according to the width that the TextBlock requires?

Thanks,

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: How can I get my custom node to size automatic
Reply #1 - Apr 21st, 2010 at 8:17am
Print Post  
Hi,

The ShapeNode.ResizeToFitText method uses a temporary TextBlock to measure the text size:

Code
Select All
var textBlock = new TextBlock
{
	Text = Text,
	TextWrapping = TextWrapping.Wrap,
	Width = double.NaN,
	Height = double.NaN,
	FontFamily = FontFamily,
	FontSize = FontSize
};

textBlock.UpdateLayout();
Size desiredSize = new Size(
	textBlock.ActualWidth + TextMargin.Left + TextMargin.Right + StrokeThickness * 2,
	textBlock.ActualHeight + TextMargin.Top + TextMargin.Bottom + StrokeThickness * 2); 



You can do something similar for your nodes, and also add the size of any additional elements in their template to desiredSize.

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


I love YaBB 1G - SP1!

Posts: 10
Joined: Apr 7th, 2010
Re: How can I get my custom node to size automatic
Reply #2 - Apr 21st, 2010 at 9:20am
Print Post  
Thanks Stoyan

That works nicely. I had something similar but was missing a couple of vital details.  Grin

Craig
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint