Articles in this section
Category / Section

How to prevent a container's size from updating when drawing a connector between child nodes of different containers in WPF Diagram (SfDiagram)?

3 mins read

In the WPF Diagram, you can restrict the Container size from updating while drawing a Connector from its child node to another container’s child Node by removing the connector from the container’s Connectors property using the connector’s events. Here’s a code example to demonstrate how to achieve this:

C# Code Snippet:

// Subscribe to the ConnectorSourceChangedEvent  
Diagram.Info as IGraphInfo).ConnectorSourceChangedEvent += ConnectorSourceChangedEvent;

private void ConnectorSourceChangedEvent(object sender, ChangeEventArgs<object, ConnectorChangedEventArgs> args)
       {
           if (((args.Item as ConnectorViewModel).SourceNode != null && (args.Item as ConnectorViewModel).SourceNode is NodeViewModel) && ((args.Item as ConnectorViewModel).TargetNode != null && (args.Item as ConnectorViewModel).TargetNode is NodeViewModel))
           {
               if (((args.Item as ConnectorViewModel).SourceNode as NodeViewModel).ParentGroup != ((args.Item as ConnectorViewModel).TargetNode as NodeViewModel).ParentGroup)
               {
                   if ((((args.Item as ConnectorViewModel).SourceNode as NodeViewModel).ParentGroup) != null)
                   {
                       ((((args.Item as ConnectorViewModel).SourceNode as NodeViewModel).ParentGroup as ContainerViewModel).Connectors as ConnectorCollection).Remove(args.Item as ConnectorViewModel);
                   }

                   if ((((args.Item as ConnectorViewModel).TargetNode as NodeViewModel).ParentGroup) != null)
                   {
                       ((((args.Item as ConnectorViewModel).TargetNode as NodeViewModel).ParentGroup as ContainerViewModel).Connectors as ConnectorCollection).Remove(args.Item as ConnectorViewModel);
                   }
               }
           }
       } 

Container Image

Conclusion

I hope you enjoyed learning about how to prevent a container’s size from updating when drawing a connector between child nodes of different containers in the WPF Diagram.
You can refer to our WPF Diagram feature tour page to learn about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied