# Blazor Diagram Events

The Telerik [Blazor Diagram](https://www.telerik.com/blazor-ui/documentation/components/diagram/overview) fires events that are related to different user actions. This article describes all these events and their event arguments:

* [`OnConnectionClick`](https://www.telerik.com/blazor-ui/documentation/components/diagram/events#onconnectionclick)
* [`OnConnectionDragStart`](https://www.telerik.com/blazor-ui/documentation/components/diagram/events#onconnectiondragstart)
* [`OnConnectionDragEnd`](https://www.telerik.com/blazor-ui/documentation/components/diagram/events#onconnectiondragend)
* [`OnShapeClick`](https://www.telerik.com/blazor-ui/documentation/components/diagram/events#onshapeclick)
* [`OnShapeDragStart`](https://www.telerik.com/blazor-ui/documentation/components/diagram/events#onshapedragstart)
* [`OnShapeDragEnd`](https://www.telerik.com/blazor-ui/documentation/components/diagram/events#onshapedragend)

## OnConnectionClick

The `OnConnectionClick` event fires when the user clicks on a connection, including the connection ends that rest on the shape boundaries. The event argument is of type [`DiagramConnectionClickEventArgs`](https://www.telerik.com/blazor-ui/documentation/api/telerik.blazor.components.diagramconnectionclickeventargs) and it provides information about the linked shapes (if they exist) or about the connection coordinates (if set).

> caption Using the Diagram OnConnectionClick event

```RAZOR.skip-repl
<TelerikDiagram OnConnectionClick="@OnDiagramConnectionClick" />

@code {
    private void OnDiagramConnectionClick(DiagramConnectionClickEventArgs args)
    {

    }
}
```

Also see the [example](https://www.telerik.com/blazor-ui/documentation/components/diagram/events#example) below.

## OnShapeClick

The `OnShapeClick` event fires when the user clicks on a shape. The event argument is of type [`DiagramShapeClickEventArgs`](https://www.telerik.com/blazor-ui/documentation/api/telerik.blazor.components.diagramshapeclickeventargs) and provides the shape `Id`.

> caption Using the Diagram OnShapeClick event

```RAZOR.skip-repl
<TelerikDiagram OnShapeClick="@OnDiagramShapeClick" />

@code {
    private void OnDiagramShapeClick(DiagramShapeClickEventArgs args)
    {

    }
}
```

Use the [Diagram JSON state](https://www.telerik.com/blazor-ui/documentation/components/diagram/overview#define-shapes-and-connections-in-json) if you need to [change the Diagram configuration](https://www.telerik.com/blazor-ui/documentation/knowledge-base/diagram-change-shape-color-onshapeclick) while persisting other user changes that are not part of the component declaration.

## OnConnectionDragStart

The `OnConnectionDragStart` event fires when the user starts dragging a connection in the Diagram. The event argument is of type [`DiagramConnectionDragStartEventArgs`](https://www.telerik.com/blazor-ui/documentation/api/telerik.blazor.components.diagramconnectiondragstarteventargs) and provides information about the connection being dragged.

> caption Using the Diagram OnConnectionDragStart event

```RAZOR.skip-repl
<TelerikDiagram OnConnectionDragStart="@OnDiagramConnectionDragStart" />

@code {
    private void OnDiagramConnectionDragStart(DiagramConnectionDragStartEventArgs args)
    {
        // args.Connections contains the dragged connections
        // args.ConnectionHandle is "source" or "target" when dragging an endpoint
    }
}
```

Also see the [example](https://www.telerik.com/blazor-ui/documentation/components/diagram/events#example) below.

## OnConnectionDragEnd

The `OnConnectionDragEnd` event fires when the user finishes dragging a connection in the Diagram. The event argument is of type [`DiagramConnectionDragEndEventArgs`](https://www.telerik.com/blazor-ui/documentation/api/telerik.blazor.components.diagramconnectiondragendeventargs) and provides the same information as `OnConnectionDragStart`.

> caption Using the Diagram OnConnectionDragEnd event

```RAZOR.skip-repl
<TelerikDiagram OnConnectionDragEnd="@OnDiagramConnectionDragEnd" />

@code {
    private void OnDiagramConnectionDragEnd(DiagramConnectionDragEndEventArgs args)
    {
        // args.Connections contains the dragged connections
    }
}
```

Also see the [example](https://www.telerik.com/blazor-ui/documentation/components/diagram/events#example) below.

## OnShapeDragStart

The `OnShapeDragStart` event fires when the user starts dragging a shape in the Diagram. The event argument is of type [`DiagramShapeDragStartEventArgs`](https://www.telerik.com/blazor-ui/documentation/api/telerik.blazor.components.diagramshapedragstarteventargs) and provides information about the shape being dragged.

The `DiagramShapeDragStartEventArgs` exposes the following property:

* `Shapes` (`List<DiagramShapeDragDescriptor>`)—the shapes being dragged. Each `DiagramShapeDragDescriptor` contains the shape `Id`.

> caption Using the Diagram OnShapeDragStart event

```RAZOR.skip-repl
<TelerikDiagram OnShapeDragStart="@OnDiagramShapeDragStart" />

@code {
    private void OnDiagramShapeDragStart(DiagramShapeDragStartEventArgs args)
    {
        // args.Shapes contains the dragged shapes
    }
}
```

Also see the [example](https://www.telerik.com/blazor-ui/documentation/components/diagram/events#example) below.

## OnShapeDragEnd

The `OnShapeDragEnd` event fires when the user finishes dragging a shape in the Diagram. The event argument is of type [`DiagramShapeDragEndEventArgs`](https://www.telerik.com/blazor-ui/documentation/api/telerik.blazor.components.diagramshapedragendeventargs) and provides the same information as `OnShapeDragStart`.

> caption Using the Diagram OnShapeDragEnd event

```RAZOR.skip-repl
<TelerikDiagram OnShapeDragEnd="@OnDiagramShapeDragEnd" />

@code {
    private void OnDiagramShapeDragEnd(DiagramShapeDragEndEventArgs args)
    {
        // args.Shapes contains the dragged shapes
    }
}
```

Also see the [example](https://www.telerik.com/blazor-ui/documentation/components/diagram/events#example) below.

## Example

The following example demonstrates all Diagram events in action.

> caption Using Diagram events

<demo metaUrl="client/diagram/events/events-1/" height="570"></demo>

## See Also

* [Live Demos: Diagram](https://demos.telerik.com/blazor-ui/diagram/overview)
* [Diagram API Reference](https://www.telerik.com/blazor-ui/documentation/api/telerik.blazor.components.telerikdiagram)
