We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Set Parent Child relation dynamically when using Data Source.

Hi Team,

I am using sfDiagram for one of my requirement, where I need to add nodes onto the diagram and then establish parent child like relation on click of button.
I am using DataSource setting to set the initial data onto the diagram, later I add multiple nodes onto the diagram, these new nodes do not have parent id specified when added. After adding the  new nodes I try to establish relation of each new node by setting parent id on click of button, but when I do that I get a error saying, "Source cannot be  null".

The exception does not provide much information and I am not able to figure out what I am missing.
I have attached a similar sample with Skeleton code. Please help.


Thank you,
Srikanth V

Attachment: MySFDiagramRelations_ea5a9dc8.zip

4 Replies

KR Karkuvel Rajan Shanmugavel Syncfusion Team October 17, 2019 10:52 AM UTC

Hi Srikanth, 
 
Reported Issue : Null Reference Issue while add parent id for the item in datasource. 
 
We are able to reproduce the reported issue and we have fixed the issue. The fix for this issue will be available in our upcoming weekly nuget which will schedule on October 22 , 2019.  
 
Before that if you need patch on any of our Main or SP release version, then please revert us with the version details. We will provide a patch on that version.   
 
Regards, 
Karkuvel Rajan S 



KR Karkuvel Rajan Shanmugavel Syncfusion Team October 22, 2019 07:19 AM UTC

Hi Srikanth,  
  
Reported Issue : Null Reference Issue while add parent id for the item in datasource.  
 
We are glad to announce that our weekly package is released successfully. We have included the fix for the reported issue in this weekly release . Please upgrade to our latest version(17.3.0.19).   
   
 
If you need patch on any of our Main or SP release version, then please revert us with the version details. We will provide a patch on that version.      
 
Regards, 
Karkuvel Rajan S 



SV Srikanth Vattipally October 25, 2019 01:59 PM UTC

Thank you so much for fixing the issue and pushing it via nuget packages, I am now able to connect the nodes dynamically.

I continuation, I have a few questions, it would be great if you could help.
  • I am using <Style TargetType="syncfusion:Node" BasedOn="{StaticResource NodeBindingStyle}"> to set common properties of the nodes that are being generated (from datasource) or dropped (from stencil) onto the sfDiagram, I am able to set properties like BorderBrush, Content, ContentTemplate etc, but when I set Constraints  (I assume they are NodeConstraints) that need to be applicable for all the nodes, it is reverted back to Default. Am I missing something? or they need to be explicitly set from code behind or my viewmodel?
  • Also similar to above I would like to know if there is a property that I can access in XAML to set SelectorViewModel.SelectorConstraints and ContextMenu for the nodes so that they are applied to all the nodes.
Thanks in advance.
Srikanth


RA Ranjitha Amirthalingam Syncfusion Team October 31, 2019 12:11 PM UTC

Hi Srikanth,  
  
Please find the response for your queries in below table.  
 
S.No 
Query  
Response  
1 
I am using <Style TargetType="syncfusion:Node" BasedOn="{StaticResource NodeBindingStyle}"> to set common properties of the nodes that are being generated (from datasource) or dropped (from stencil) onto the sfDiagram, I am able to set properties like BorderBrush, Content, ContentTemplate etc, but when I set Constraints  (I assume they are NodeConstraints) that need to be applicable for all the nodes, it is reverted back to Default. Am I missing something? or they need to be explicitly set from code behind or my viewmodel?  
 
We can set Shape and ShapeStyle properties in XAML as common for Node. If we want to set other public properties (of Node) as common, then please create a custom NodeViewModel and set those properties in the Custom NodeViewModel Constructor . 
 
We have provided code example to set Menu and Constraints properties as common to all nodes. Please refer the code example as below.  
 
Code Example: 
public class CustomNode : NodeViewModel 
{ 
        public CustomNode() 
        { 
            this.Constraints = this.Constraints | NodeConstraints.Menu | NodeConstraints.AspectRatio | NodeConstraints.AllowDrop; 
            this.Constraints = this.Constraints & ~NodeConstraints.InheritMenu; 
            this.Menu = new DiagramMenu(); 
            this.Menu.MenuItems = new ObservableCollection<DiagramMenuItem>(); 
            DiagramMenuItem mi = new DiagramMenuItem() 
            { 
                Content = "Delete", 
                Command = DiagramCommands.Delete 
            }; 
            (this.Menu.MenuItems as ICollection<DiagramMenuItem>).Add(mi); 
               } 
} 
 
Also similar to above I would like to know if there is a property that I can access in XAML to set ContextMenu for the nodes so that they are applied to all the nodes.  
  
2 
I would like to know if there is a property that I can access in XAML to set SelectorViewModel.SelectorConstraints 
Please refer to the below code example to set SelectorViewModel.SelectorConstraints in XAML.  
  
Code Example:  
<Syncfusion:SfDiagram.SelectedItems>  
   <Syncfusion:SelectorViewModel SelectorConstraints="Resizer"/>  
</Syncfusion:SfDiagram.SelectedItems>  
  
 
Regards, 
Ranjitha A. 


Loader.
Live Chat Icon For mobile
Up arrow icon