# 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 dragging operation is about to be performed.

* **Drag**- occurs when dragging operation is performed.

## Serialization Events

* **Deserialized**- occurs when deserialization process end.

* **Serialized**- occurs when serialization process end.

* **ShapeDeserialized**- occurs when shape is deserialized.

* **ShapeSerialized**- occurs when shape is serialized.

* **ConnectionDeserialized**- occurs when connection is deserialized.

* **ConnectionSerialized**- occurs when connection is serialized.

* **MetadataDeserialized**- occurs when metadata is deserialized.

* **MetadataSerialized**- occurs when metadata is serialized.

## Click Events

* **ShapeClicked**- occurs when shape is clicked.

* **ShapeDoubleClicked**- occurs when shape is double clicked.

* **ConnectionClicked**- occurs when connection is clicked.

## Command Events

* **CommandExecuted**- occurs when DiagramCommand is executed.

## Items Collection Events

* **ItemsChanging**- occurs while the Items collection is changing its items.

* **ItemsChanged**- occurs when Items collection is changed.

## Connection Manipulation Events

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

* **ConnectionManipulationCompleted**- event that 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**- 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**- 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**- 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**- 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

* **GroupsChanged**- occurs when the root level logical group is created or ungrouped.

## Pan and Zoom Events

* **PositionChanged**- fires when the position of the diagram is changed.

* **ZoomChanged**- fires 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.

## 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**.

> note 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**.
