# Diagram Events

This topic covers the specific events exposed by the **RadDiagram**. The events are grouped by their general purpose.

## Selection Events

* **PreviewSelectionChanged**: Occurs when the selection of the diagram starts changing.

* **SelectionChanged**: Occurs when the selected item/items are changed.

* **SelectionBoundsChanged**: Occurs when the selection adorner rectangle is changed.

## Resizing Events

* **PreviewResize**: Occurs when item/items is/are about to be resized.

* **Resize**: Occurs when item/items is/are resized.

## Rotation Events

* **PreviewRotate**: Occurs when item/items is/are about to be rotated.

* **Rotate**: Occurs when item/items is/are rotated.

## Drag Events

* **PreviewDrag**: Occurs when a dragging operation is about to be performed.

* **Drag**: Occurs when a dragging operation is performed.

## Serialization Events

* **Deserialized**: Occurs when a deserialization process ends.

* **Serialized**: Occurs when a serialization process ends.

* **ShapeDeserialized**: Occurs when a shape is deserialized.

* **ShapeSerialized**: Occurs when a shape is serialized.

* **ConnectionDeserialized**: Occurs when a connection is deserialized.

* **ConnectionSerialized**: Occurs when a connection is serialized.

* **MetadataDeserialized**: Occurs when metadata is deserialized.

* **MetadataSerialized**: Occurs when metadata is serialized.

## Click Events

* **ShapeClicked**: Occurs when a shape is clicked.

* **ShapeDoubleClicked**: Occurs when a shape is double clicked.

## Command Events

* **CommandExecuted**: Occurs when a DiagramCommand is executed.

## Items Collection Events

* **ItemsChanging**: Occurs while the Items collection is changing its items.

* **ItemsChanged**: Occurs when the Items collection is changed.

## Connector Events

* **ConnectorActivationChanged**: Occurs after a connector has been activated or deactivated.

## Connection Manipulation Events

* **ConnectionManipulationStarted**: This event is raised by a **RadDiagram** to inform that a connection manipulation is starting.

* **ConnectionManipulationCompleted**: This event is raised by a **RadDiagram** to inform that a connection manipulation is ending.

When you manipulate a connection you have two different stages of the process - start of the manipulation and end of the manipulation. When you start manipulating a connection - for instance creating a new connection or detaching a connection, the **ConnectionManipulationStarted** event is fired. When the manipulation is in its ending stage - the **ConnectionManipulationCompleted** event is fired. And it is important to work with both events in order to cover all parts of a single connection manipulation. And it is also very crucial to note that both events are designed to represent **preview** events and their purpose is to allow you to **cancel a connection manipulation**.

This means that the **ConnectionManipulationStarted** event is fired before the manipulation of a connection is truly started - in this case the **EventArgs (e)** of the event hold the **e.Connection** that is going to be manipulated (or created), and the **e.Shape** and the **e.Connector** that are part of the manipulation. In case you're starting to drag a new connection out of the connector of a shape, then the **ConnectionManipulationStarted** will be fired before the connection is created. This way you can cancel the process and therefore the **e.Connection** property will be null, while the **e.Shape** and **e.Connector** properties will hold the shape and the connector where the drag is originating from. And if you're detaching a connection, again you'll have to handle the **ConnectionManipulationStarted** event as you're starting a new manipulation of a connection. When detaching a connection, the **e.Connection** property will reflect the connection that is being detached and the **e.Shape** property will reflect the shape from which the connection is detached. However, please note that in this case the **e.Shape IncomingLinks/OutgoingLinks** collections will still hold a reference of the current connection as the **ConnectionManipulationStarted** event is a preview event and when it is fired, the connection isn't really detached yet.

The same logic applies for the **ConnectionManipulationCompleted** event - it is fired just before a connection manipulation is over - for example when attaching a connection to a shape. Again you'll have a reference of the **e.Connection** that is being attached and the **e.Shape** to which the connection will be attached, but at this point the connection is still not attached and therefore its **SourceShape/TargetShape** properties are not updated.

The arguments of both events expose a **ManipulationStatus** property. It serves as an indicator for the status of the current connection manipulation. This property is an enumeration that provides the following members:

* **Attaching**: This represents the status of a connection that is currently being attached to a shape. This is the status indicated by a **ConnectionManipulationStarted** event when a connection is created by dragging it out of a connector or in a **ConnectionManipulationCompleted** when a connection is being attached to a new connector.

* **Detaching**: This represents the status of a connection that is currently being detached from a shape. Please note that this status can only be indicated by a **ConnectionManipulationStarted** event as the detaching of a connection can only be in the beginning of a manipulation.

* **Moving**: This represents the status of a connection that is currently being moved. Usually this is a status indicated by a **ConnectionManipulationStarted** while moving a floating connection.

* **Moved**: This represents the status of a connection that was moved. Usually this is a status indicated by a **ConnectionManipulationCompleted** event fired after releasing the mouse to create a floating connection.

## Layout Events

* **DiagramLayoutComplete**: Occurs when the Layout operation has completed.

## Grouping Events

* **GroupsChanged**: Occurs when the root level logical group is created or ungrouped.

## Pan and Zoom Events

* **PreviewPan**: Occurs before a pan operation have been performed.

* **Pan**: Occurs when a pan operation has been performed.

* **PositionChanged**: Occurs when the position of the diagram is changed.

* **ViewportChanged**: Occurs when the viewport of the diagram is changed.

* **PreviewZoom**: Occurs before a zoom operation have been performed.

* **ZoomChanged**: Occurs when a zoom operation has been performed.

## Container Generation Events

* **VisualChildrenChanged**: Occurs when a visual object (RadDiagramShape or RadDiagramConnection) is added or removed in the ItemsHost of the Diagram.

* **GraphSourceChanged**: Occurs when the GraphSource is changed and all DiagramItems are properly measured.

* **GraphSourceChanging**: Occurs when the GraphSource starts changing.

## AdditionalContent Events

* **PreviewAdditionalContentActivated**: This event is raised by a **RadDiagram** to inform layouts that the additional content is going to be activated. The event handler receives two arguments:

  * The **sender** argument contains the **RadDiagram** This argument is of type **object**, but can be cast to the **RadDiagram** type.

  * An **AdditionalContentActivatedEventArgs** object, that gives you access to a **ContextItems** collection. This collection of **IDiagramItem** objects represents the items that have activated the additional content. In most cases it contains a single item - the **RadDiagramItem** that has activated the **SettingsPane**.

  > tip Please note that you can handle this event in order to disable the **AdditionalContent (SettingsPane)** from displaying on certain **RadDiagramItems**.

* **AdditionalContentActivated**: This event is raised by a **RadDiagram** to inform layouts that the additional content has been activated. The event handler receives two arguments:

  * The **sender** argument contains the **RadDiagram** This argument is of type **object**, but can be cast to the **RadDiagram** type.

  * An **AdditionalContentActivatedEventArgs** object, that gives you access to a **ContextItems** collection. This collection of **IDiagramItem** objects represents the items that have activated the additional content. In most cases it contains a single item - the **RadDiagramItem** that has activated the **SettingsPane**.

## See Also

* [Getting Started](https://www.telerik.com/products/wpf/documentation/controls/raddiagram/getting-started)
* [Populating with Data](https://www.telerik.com/products/wpf/documentation/controls/raddiagram/populating-with-data/data-overview)
* [Shapes](https://www.telerik.com/products/wpf/documentation/controls/raddiagram/diagram-items/shape/raddiagrams-features-shapes)
* [Connections](https://www.telerik.com/products/wpf/documentation/controls/raddiagram/diagram-items/raddiagrams-features-connections)
* [Clipboard Operations](https://www.telerik.com/products/wpf/documentation/controls/raddiagram/items-manipulation/raddiagrams-features-clipboard)
* [Removing Items](https://www.telerik.com/products/wpf/documentation/controls/raddiagram/items-manipulation/raddiagrams-features-delete)
* [Undo and Redo](https://www.telerik.com/products/wpf/documentation/controls/raddiagram/features/raddiagrams-undo-redo)
* [Items Events](https://www.telerik.com/products/wpf/documentation/controls/raddiagram/events/raddiagrams-item)
