ID, SourceNodeID etc... always null from a ConnectorViewModel

Hi,

I'm trying to get the ID, SourceNodeID and TargetNodeID from a ConnectorViewModel in the ItemAdded event, but it always arrives in as null.

How do I get a reference to the ConnectorViewModel with all it's underlying data whan a user creates a connection between 2 Nodes ?

(diagram.Info as IGraphInfo).ItemAdded += item_added;

private void item_added(object sender, ItemAddedEventArgs args)

{

if (args.Item is ConnectorViewModel)

{

AddToMessageLog("ConnectorViewModel Added ");

ConnectorViewModel connector = args.Item as ConnectorViewModel;

MessageBox.Show(connector.SourceNodeID.ToString());

}

}

I'm not only trying to learn sfDiagram for WPF, but also trying to learn WPF and C#.NET at the same time as I've come from a Web Developer background, so sorry if the question is a bit simple.

Thanks in advance :)


1 Reply

KR Karkuvel Rajan Shanmugavel Syncfusion Team July 3, 2023 08:44 AM UTC

Hi Craig,


ItemAdded event is fired when we add a new diagram element in diagram page. We have specific events to get the values of the diagram elements. Please use the ConnectorEditing, ConnectorSourceChangedEvent, and ConnectorTargetChangedEvent to get the Connector’s information. Please find the code example below.


Code – Examples:


 

            (Diagram.Info as IGraphInfo).ConnectorSourceChangedEvent += MainWindow_ConnectorSourceChangedEvent;

            (Diagram.Info as IGraphInfo).ConnectorTargetChangedEvent += MainWindow_ConnectorTargetChangedEvent;

            (Diagram.Info as IGraphInfo).ConnectorEditing += MainWindow_ConnectorEditing;

 

        private void MainWindow_ConnectorEditing(object sender, ConnectorEditingEventArgs args)

        {

            if(args.DragState == DragState.Completed)

            {

                // Based on your condition you can implement your codes

            }

        }

 

        private void MainWindow_ConnectorTargetChangedEvent(object sender, ChangeEventArgs<object, ConnectorChangedEventArgs> args)

        {

            if(args.NewValue.DragState == DragState.Completed)

            {

                // Based on your condition you can implement your codes

            }

        }

 

        private void MainWindow_ConnectorSourceChangedEvent(object sender, ChangeEventArgs<object, ConnectorChangedEventArgs> args)

        {

            if (args.NewValue.DragState == DragState.Completed)

            {

                // Based on your condition you can implement your codes

            }

        }

 


Regards,

Karkuvel Rajan S


Loader.
Up arrow icon