Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Dynamic resizing of templated node (Read 1068 times)
KillaChris19
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 8
Joined: Mar 9th, 2018
Dynamic resizing of templated node
May 14th, 2019 at 7:05am
Print Post  
Hello,
I have some problems with templated nodes and resizing.
The content of my nodes is created dynamically. The user even has the possiblity to show/hide some contents, which are displayed inside the nodes. So it is not possible to set a fixed size for the nodes.
So I created a class, which derives from TemplatedNode.
And I added a method "ResizeToFit" to this class.

Code
Select All
public void ResizeToFit()
{
    if (GetVisualChild(0) is UIElement child)
    {
        child.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
        SetBounds(new Rect(Bounds.Left, Bounds.Top, child.DesiredSize.Width, child.DesiredSize.Height), true, true);
    }
} 



At first I'm adding all the nodes and the connections to the Diagram.
Afterwards I call my ResizeToFit method to set the correct size on all of the nodes.
And in the end I'm using a LayeredLayout to position the nodes.
This has to be done in this order, otherwise the layout wouldn't work correctly as the right size of the nodes wasn't calculated before.

In most of the cases this solution works well. But there are some cases where a long text is displayed in the node. So I've set a MaxWidth that the node doesn't get too big. So I had to enable TextWrapping for the TextBlock, which displays this long text.
And this is where the problem starts. As long as the text only needs one line everything is alright. But the height of the nodes isn't calculated correctly, when the next spans over multiple lines.

I think this problem occurs, because the TextBlock isn't rendered when the calculation of the size is done. So it is treated as a TextBlock with only one line.

When I override the OnRender method and put the resizing in this method the size is calculated correctly, but this is causing several other problems.

So is there any easy solution, which could be used to achive the auto-sizing of a node?
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3152
Joined: Oct 19th, 2005
Re: Dynamic resizing of templated node
Reply #1 - May 14th, 2019 at 11:22am
Print Post  
Hi,

Have you set MaxWidth on the TextBlock itself, on the node, or some element between them? This might have some effect on the Measure result. Also if you are doing the measurements in window's constructor, try moving them to the _Loaded event handler - otherwise there might be some differences caused by the text block not connected to the visual hierarchy yet.

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