Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic ControlNode and Control resize (Read 1848 times)
baba
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 16
Joined: Jan 20th, 2010
ControlNode and Control resize
Sep 6th, 2010 at 1:16pm
Print Post  
Hi all,
I've implemented a class which extends ControlNode in order to embed a custom UserControl in a DIagramNode.

The inner control has, in turn, a TextBox inside, which obviously shows some text.

The lenght of the text is not known at run-time and the UserControl has been given the value "Auto" for its Width and Height properties.

Now the question...

I'd like the ControlNode to be resized automatically at the end of the Load process so that it would actually adjust its width to show the entire inner control (and, because of that, the entire TextBox and text - this is the reason of the post).

I've been searching the forum and found this http://mindfusion.eu/Forum/YaBB.pl?board=diaglite_disc;action=display;num=128253...

...I've tried something but it's not working and I'm not sure I've understood.

Can anyone explain how to solve this task in detail please?

Cheers,
baba.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: ControlNode and Control resize
Reply #1 - Sep 6th, 2010 at 5:24pm
Print Post  
If there was just a TextBlock hosted in the ControlNode, you can auto-size it by calling Measure and checking the DesiredSize, or by forcing the layout to complete via UpdateLayout and getting ActualWidth and ActualHeight:

Code
Select All
var tb = new TextBlock();
var cn = new ControlNode(diagram, tb);
tb.Text = "test test 12345678\nline 2\none more line";
diagram.Nodes.Add(cn);

tb.InvalidateMeasure();
tb.UpdateLayout();
cn.Bounds = new Rect(
	cn.Bounds.X, cn.Bounds.Y,
	tb.ActualWidth, tb.ActualHeight); 



However if the user control contains its TextBlock inside a Canvas or inside a grid with fixed Width or Height for a ColumnDefinition or RowDefinition, calling Measure or UpdateLayout on the control won't give you the size that fits the text. In such case you might use a temporary TextBlock as shown here:
http://mindfusion.eu/Forum/YaBB.pl?board=diaglite_disc;action=display;num=127649...

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