Changing node size when it has a data template

I am having trouble changing the node size after I have assigned a DataTemplate to the node.

Here is the DataTemplate I am using. It's pretty simple:


Next, here is the code where I create a node that uses this data template and add it to the diagram:

SfDiagram diagram = new SfDiagram();
diagram.PageSettings.ShowGrid = true;
diagram.PageSettings.SnapToGrid = true;
diagram.PageSettings.GridSize = 50;

Node my_node = new Node();
my_node.Template = Application.Current.Resources["AddNodeTemplate"] as DataTemplate;
my_node.OffsetX = 400;
my_node.OffsetY = 500;
my_node.Width = 250;
my_node.Height = 250;
diagram.AddNode(my_node);
this.Content = diagram;

The problem is that the node doesn't really respond to my size request. I could set the Width and Height to anything, but the node always stays the same size (and that size is not "250" as seen in my code above). The reason I know it's not "250" as I have set in my code is because I have grid lines turned on, and the grid line spacing is set to "50".

I've linked a screenshot so you can see what it actually looks like: https://utdallas.app.box.com/s/ottwnolil0fdeqyukxf2ec2hxbg7hcse

So how do I get it to be the size I actually want while also being able to use templates to adjust the look/feel of the node?




6 Replies

DS Devaraj Sekar Syncfusion Team February 1, 2021 09:19 AM UTC

Hi David, 
Thank you for contacting Syncfusion support. 
On analyzing further with the mentioned requirement, to achieve the requirement “Node should resize when template is added” we need to set size fo the template added in the node object. We have prepared a sample based on the mentioned requirement, which can be downloaded from the below link. 
Kindly let us know whether the provided sample fulfills your requirement. 
Regards, 
Devaraj S 




DP David Pruitt February 1, 2021 09:54 PM UTC

Devaraj,

Thank you for the reply, but unfortunately this doesn't really solve the root problem. In fact, there seem to be two root problems.

Problem #1: The "size" specified in the Node constructor is in different units than the "size" specified in the data template. You can see this very easily in your own example if you simply comment out one line of code: n1.Template = dataTemplate;

Try running the code from your example with this line active and then again with this line commented out. You will see that the size of the node is very different on each run, but it shouldn't be. It should be identical.

Problem #2: The "size" of the node as specified in the Node constructor seems to have zero effect if a data template is assigned. This should not be the case. The data template should be scaled up or down to match the size of the node, but this is not happening.




DS Devaraj Sekar Syncfusion Team February 2, 2021 11:08 AM UTC

Hi David, 
Thank you for the update. 
S. No 
Query 
Answer 
1.        
Problem #1: The "size" specified in the Node constructor is in different units than the "size" specified in the data template. You can see this very easily in your own example if you simply comment out one line of code: n1.Template = dataTemplate; 
 
Try running the code from your example with this line active and then again with this line commented out. You will see that the size of the node is very different on each run, but it shouldn't be. It should be identical. 
 
Problem #2: The "size" of the node as specified in the Node constructor seems to have zero effect if a data template is assigned. This should not be the case. The data template should be scaled up or down to match the size of the node, but this is not happening. 
On analyzing further with the provided information, the node size property assigned in constructor works as expected from our side. The node object will be rendered based on device density in SfDiagram. As mentioned, the template and node size are in different ratio. 
 
We were able to reproduce the reported behavior with “Template size get scaled up while assigning to Node object in SfDiagram Android platform”. We will update the further validation details on 4th February 2021. 

Regards, 
Devaraj S 



DS Devaraj Sekar Syncfusion Team February 4, 2021 12:43 PM UTC

Hi David, 
Thank you for the patience. 
On analyzing further with the provided information, to achieve the mentioned requirement “To maintain node and template size in same ratio” the template size should be matched with device density and it can be achieved at design level. We have prepared a sample based on the mentioned requirement, which can be downloaded from the below link. 
Code snippet: 
 
////Device density 
var mainDisplayInfo = DeviceDisplay.MainDisplayInfo; 
 
  
Kindly let us know whether the provided sample fulfils your requirement. 
Regards,
Devaraj S 



DP David Pruitt February 5, 2021 10:08 AM UTC

Thank you for your latest reply. That does seem to solve that issue.

This is troubling, however. If you have to device the width and height by the display density for any data template, that must indicate that something in your API is not using device-independent pixels. Is there a reason for this?


DS Devaraj Sekar Syncfusion Team February 8, 2021 02:47 PM UTC

Hi David, 
 
Thank you for the update. 
 
The mentioned support with “To maintain node and template size in same ratio” has been added it to our feature request list, we will implement the mentioned feature in any our upcoming release. We will let you know when this feature is implemented. The status of implementation can be tracked through our Features Management System:  
 
 
Kindly let us know if you require any further assistance. 
 
Regards, 
Devaraj S 


Loader.
Up arrow icon