Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic How to have TemplatedNode auto size to content (Read 1144 times)
notsureusa
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 3
Joined: Mar 5th, 2018
How to have TemplatedNode auto size to content
Mar 8th, 2018 at 1:02pm
Print Post  
I've created a custom TemplatedNode that has contents with varying widths and heights and want the bounds to be different for each node.  How can one accomplish this?
  
Back to top
 
IP Logged
 
Lyubo
God Member
*****
Offline


MindFusion team

Posts: 511
Joined: Jun 17th, 2010
Re: How to have TemplatedNode auto size to content
Reply #1 - Mar 8th, 2018 at 2:42pm
Print Post  
Hi,

If you're using a custom class inheriting TemplateNode, you can add the following method, which can be used to resize the node according to it's contents:
Code
Select All
public void ResizeToFit()
{
        var child = GetVisualChild(0) as UIElement;
        if (child != null)
        {
            child.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
            var childSize = child.DesiredSize;
            SetBounds(new Rect(Bounds.Left, Bounds.Top, childSize.Width, childSize.Height), true, true);
        }
} 



You can call this method after creating the node, if you're using a static template, or in response to a value changed handler, if you are using a template with bound fields.

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