How to list connectors that are attached to another connector.

Hello Syncfusion staff,

I have a custom ConectorViewModel that accepts other connections from and to nodeViewModels. I need to expose those links; thus, being able to modify their style. “This.Ports” collection seems the most probable way of doing it, but it is not an iterable object. So, I would like to know how to get those connections. If possible, would you mind including a code example?

Thank you,

Tomas.


3 Replies

KR Karkuvel Rajan Shanmugavel Syncfusion Team October 31, 2021 06:09 PM UTC

Hi Tomas, 
 
Requirement: Need to get the list of Connectors that are attached to another connector. 
 
We have analyzed your requirement and prepare a simple sample based on your requirement. In the sample we have used ConnectorPort to attach other Connectors in the sample and we have iterate the connectors from the Ports and changed their styles. Please find the sample and video in below links. 
 
 
 
If the provided sample doesn’t satisfy your requirement please revert us with more details of your requirement with some images or videos. 
 
Regards, 
Karkuvel Rajan S 



TO Tomas November 1, 2021 12:58 AM UTC

Hello Karkuvel,,

The provided solution does not satisfy the requirement. I need to detect all the connectors that are connected to the custom ConnectorViewModel, and to list them, so I can change their styles and track to which node they are linked from the custom Connector.

Thank you,

Tomas.



KR Karkuvel Rajan Shanmugavel Syncfusion Team November 1, 2021 01:17 PM UTC

Hi Tomas, 
 
Requirement: Need to list all the connectors. 
 
We have analyzed your requirement and from our analysis we know that you want to list all the connectors that are connected from and to of the selected connector. In our SfDiagram control, if you need to connect a new connector with an existing connector then you need to use a connector port in the existing connector. We have provided the code example below to get the list of connectors of the selected connectors using Ports property. 
 
Code example: 
 
 
        ObservableCollection<ConnectorViewModel> RelatedConnectors = new ObservableCollection<ConnectorViewModel>(); 
 
        private void ChangeStyle_Click(object sender, RoutedEventArgs e) 
        { 
            if((Diagram.SelectedItems as SelectorViewModel).SelectedItem is ConnectorViewModel) 
            { 
                ConnectorViewModel selectedconnector = (Diagram.SelectedItems as SelectorViewModel).SelectedItem as ConnectorViewModel; 
 
                if(selectedconnector.Ports != null && selectedconnector.Ports is PortCollection) 
                { 
                    foreach(ConnectorPortViewModel port in selectedconnector.Ports as PortCollection) 
                    { 
                        foreach(ConnectorViewModel conns in (port.Info as IConnectorPortInfo).InConnectors as IEnumerable<IConnector>) 
                        { 
                            RelatedConnectors.Add(conns); 
                        } 
 
                        foreach (ConnectorViewModel conns in (port.Info as IConnectorPortInfo).OutConnectors as IEnumerable<IConnector>) 
                        { 
                            RelatedConnectors.Add(conns); 
                        } 
                    } 
                } 
            } 
        } 
 
 
 
If the provided code example doesn’t satisfy your requirement please revert us with more details of your requirement with some images or videos. 
 
Regards, 
Karkuvel Rajan S 


Loader.
Up arrow icon