Event Mechanism in WPF Diagram (classic)

This section describes several events triggered and handled while using Essential Diagram WPF in the following topic:

Events for Nodes and Connections

Diagram control has several events which respond to several actions performed on nodes and connections.

The various events and their descriptions are explained in the following table.

Event Description Arguments
NodeClick Raised when the node is clicked.
Event cannot be canceled.
Node – Node on which event is raised.
NodeDoubleClick Raised when the node is clicked twice in succession.
Event cannot be canceled.
Node – Node on which event is raised.
NodeStartLabelEdit Raised when the label editing on the node is started.
Event cannot be canceled.
NewLabelValue – The new label value.OldLabelValue – the old label value.Node - Node on which event is raised.
NodeLabelChanged Raised when the node's label value is changed.
Event cannot be canceled.
NewLabelValue – The new label value.OldLabelValue – the old label value.Node - Node on which event is raised.
NodeDragStart Raised when the node is dragged.
Event cannot be canceled.
Node – Node on which event is raised.
NodeDragEnd Raised when the drag operation on node is complete.Event cannot be canceled. Node – Node on which event is raised.
NodeResizing Raised when the resize operation is being performed.
Event cannot be canceled.
Node – Node on which event is raised.
NodeResized Raised after the node is resized.
Event cannot be canceled.
Node – Node on which event is raised.
NodeRotationChanging Raised when the node is being rotated.
Event cannot be canceled.
Node – Node on which event is raised.
NodeRotationChanged Raised after the node is rotated.
Event cannot be canceled.
Node – Node on which event is raised.
ConnectorDoubleClick Raised when the Connector is clicked twice in succession.
Event cannot be canceled.
Connector – Connector on which the event is raised.Head Node – Head Node of the connector.Tail Node – Tail Node of the connector.
ConnectorStartLabelEdit Raised when the label editing on the Connector is started.
Event cannot be canceled.
Connector – Connector on which the event is raised.Head Node – Head Node of the connector.Tail Node – Tail Node of the connector.OldLabelValue – the old label value.
ConnectorLabelChanged Raised when the connector's label value is changed.
Event cannot be canceled.
Connector – Connector on which the event is raised.Head Node – Head Node of the connector.Tail Node – Tail Node of the connector.OldLabelValue – the old label value.NewLabelValue – The new label value.
ConnectorDragStart Raised when either ends of the connector is dragged.
Event cannot be canceled.
Connector – Connector on which the event is raised.FixedNodeEnd – Node on which the connection is fixed.MovableNodeEnd – The old Node on which the Connector was connected.
ConnectorDragEnd Raised when the drag operation is complete.
Event cannot be canceled.
Connector – Connector on which the event is raised.FixedNodeEnd – Node on which the connection is fixed.HitNodeEnd – The new node on which the Connector is getting connected.
NodeDrop Raised when a shape from the SymbolPalette is dropped on the page.
Event cannot be canceled.
DroppedNode – The new node just dropped from SymbolPalette.SymbolPaletteItemName – The name of the SymbolPalette item, which is dropped on the page.
HeadNodeChanged Raised when the HeadNode of the connector is changed
Event cannot be canceled.
Connector – The connector whose HeadNode is changed.PreviousNode – The old Node on which the HeadNode of the Connector was connector.CurrentNode - The new Node on which the HeadNode of the Connector is connector.
TailNodeChanged Raised when the TailNode of the connector is changed.
Event cannot be canceled.
Connector – The connector whose HeadNode is changed.PreviousNode – The old Node on which the TailNode of the Connector was connector.CurrentNode - The new Node on which the TailNode of the Connector is connector.
ConnectorDrop Raised when the connector is dropped on the page.
Event cannot be canceled.
DroppedConnector – Connector on which the event is raised.
BeforeConnectionCreate Raised when a new connection is being made.
Event cannot be canceled.
Connector – The connector whose HeadNode is changed.
AfterConnectionCreate Raised after the connection has been made.
Event cannot be canceled.
Connector – Connector on which the event is raised.FixedNodeEnd – Node on which the connection is fixed.HitNodeEnd – The new node on which the Connector is getting connected.
NodeSelected Raised when a node is selected.
Event cannot be canceled.
Node – Node on which event is raised.
NodeUnSelected Raised when a node is not selected.
Event cannot be canceled.
Node – Node on which event is raised.
NodeDeleting Raised before a node is deleted from the model.
Event cannot be canceled.
DeletedNode – Node which is going to get deleted.
NodeDeleted Raised when a node is deleted from the model.
Event cannot be canceled.
DeletedNode – Node which is deleted.
ConnectorDeleting Raised before a line connector is deleted from the model.
Event cannot be canceled.
DeletedLineConnector – LineConnector which is getting deleted.
ConnectorDeleted Raised when a line connector is deleted from the model.
Event cannot be canceled.
DeletedLineConnector – LineConnector which is deleted.
PreviewNodeDrop Raised before a node is dropped on the page.
Event cannot be canceled.
Node – Node on which event is raised.
PreviewConnectorDrop Raised before a line connector is dropped on the page.
Event cannot be canceled.
Connector – Connector on which the event is raised.
NodeMoved(event is fired before nudge operation is completed) Raised when the nudge operation on node is completed.
Event cannot be canceled.
Node – Node on which event is raised.oldOffset – The old offset value before nudge operation.newOffset – The new offset value after performing nudge operation.

The events can be specified using DiagramView object as follows.

  • For instance, NodeClick event can be specified in the following way.
  • html
  • <sfdiagram:DiagramView Name="diagramView" NodeClick="diagramView_NodeClick">
    
    </sfdiagram:DiagramView>
  • c#
  • diagramView.NodeClick += new NodeEventHandler(diagramView_NodeClick);
  • vbnet
  • AddHandler diagramView.NodeClick, AddressOf diagramView_NodeClick
    • And then the event handler can be specified in the code behind as follows.
  • c#
  • //Event Handler
    
    void diagramView_NodeClick(object sender, NodeRoutedEventArgs evtArgs)
    
    {
    
    //user specified code
    
    }
  • vbnet
  • 'Event Handler
    
    Private Sub diagramView_NodeClick(ByVal sender As Object, ByVal evtArgs As NodeRoutedEventArgs)
    
         'user specified code
    
    End Sub
    • As another example, the ConnectorDoubleClick event can be specified in the following way.
  • html
  • <sfdiagram:DiagramView Name="diagramView" ConnectorDoubleClick="diagramView_ConnectorDoubleClick">
    
    </sfdiagram:DiagramView>
  • c#
  • diagramView.ConnectorDoubleClick += new ConnChangedEventHandler(diagramView_ConnectorDoubleClick);
  • vbnet
  • AddHandler diagramView.ConnectorDoubleClick, AddressOf diagramView_ConnectorDoubleClick

    And then the event handler can be specified in the code behind as follows.

  • c#
  • // Event Handler
    
    void diagramView_ConnectorDoubleClick(object sender, ConnRoutedEventArgs evtArgs)
    
    {
    
    // user specified code
    
    }
  • vbnet
  • 'Event Handler
    
    Private Sub diagramView_ConnectorDoubleClick(ByVal sender As Object, ByVal evtArgs As ConnRoutedEventArgs)
    
         'user specified code
    
    End Sub
    • NodeMoved and NodeDrop events
  • c#
  • diagramView.NodeMoved += new NodeNudgeEventHandler(diagramView_NodeMoved);
    
    void diagramView_NodeMoved(object sender, NodeNudgeEventArgs evtArgs)
    
    {
    
    }
    
    
    
    diagramView.NodeDrop += new NodeNudgeEventHandler(diagramView_LineMoved);
    
    void diagramView_NodeDrop(object sender, NodeNudgeEventArgs evtArgs)
    
    {
    
    }
  • vbnet
  • Private diagramView.NodeMoved += New NodeNudgeEventHandler(AddressOf diagramView_NodeMoved)
    
    Private Sub diagramView_NodeMoved(ByVal sender As Object, ByVal evtArgs As NodeNudgeEventArgs)
    
    End Sub
    
    
    
    Private diagramView.NodeDrop += New NodeNudgeEventHandler(AddressOf diagramView_LineMoved)
    
    Private Sub diagramView_NodeDrop(ByVal sender As Object, ByVal evtArgs As NodeNudgeEventArgs)
    
    End Sub