# Diagram Data Binding

This article explains how to bind the Diagram component to a data source using descriptor classes. Data binding provides an alternative to defining shapes and connections declaratively with tags.

The Diagram supports binding to collections of shapes and connections through two main parameters:

* `ShapesData`—accepts a `List<DiagramShapeDescriptor>` that defines the shapes and their properties.
* `ConnectionsData`—accepts a `List<DiagramConnectionDescriptor>` that defines the connections between shapes and their properties.

The descriptor classes mirror the properties of the declarative tags [`<DiagramShape>`](https://www.telerik.com/blazor-ui/documentation/components/diagram/shapes) and [`<DiagramConnection>`](https://www.telerik.com/blazor-ui/documentation/components/diagram/connections), allowing you to configure the Diagram elements programmatically.

## Descriptor Classes

The data binding mechanism uses descriptor classes that correspond to the declarative component tags. For each tag, there is a descriptor class with the same properties:

* [`DiagramShapeDescriptor`](https://www.telerik.com/blazor-ui/documentation/api/telerik.blazor.components.diagramshapedescriptor)—corresponds to `<DiagramShape>` and contains properties like `Id`, `X`, `Y`, `Width`, `Height`, `Fill`, `Content`, and more.
* [`DiagramConnectionDescriptor`](https://www.telerik.com/blazor-ui/documentation/api/telerik.blazor.components.diagramconnectiondescriptor)—corresponds to `<DiagramConnection>` and contains properties like `FromId`, `ToId`, `Stroke`, `Content`, and more.

Nested properties (such as `Fill`, `Stroke`, and `Content`) also have their own descriptor classes:

* [`DiagramShapeFillDescriptor`](https://www.telerik.com/blazor-ui/documentation/api/telerik.blazor.components.diagramshapefilldescriptor)—defines the fill color and gradient of a shape.
* [`DiagramShapeContentDescriptor`](https://www.telerik.com/blazor-ui/documentation/api/telerik.blazor.components.diagramshapecontentdescriptor)—defines the text and text color displayed inside a shape.
* [`DiagramShapeContentBlockDescriptor`](https://www.telerik.com/blazor-ui/documentation/api/telerik.blazor.components.diagramshapecontentblockdescriptor)—defines a block inside the Shape that can hold text or image children.
* [`DiagramShapeContentBlockDescriptor`](https://www.telerik.com/blazor-ui/documentation/api/telerik.blazor.components.diagramshapecontentblockchilddescriptor)—defines a single child within a Shape content block.
* [`DiagramConnectionStrokeDescriptor`](https://www.telerik.com/blazor-ui/documentation/api/telerik.blazor.components.diagramconnectionstrokedescriptor)—defines the stroke color and width of a connection.
* [`DiagramConnectionContentDescriptor`](https://www.telerik.com/blazor-ui/documentation/api/telerik.blazor.components.diagramconnectioncontentdescriptor)—defines the text and text color displayed on a connection.
* [`DiagramConnectionEditableDescriptor`](https://www.telerik.com/blazor-ui/documentation/api/telerik.blazor.components.diagramconnectioneditabledescriptor)—configures connection editing behavior, including point editing, dragging, and removal.
* [`DiagramConnectionEditablePointsDescriptor`](https://www.telerik.com/blazor-ui/documentation/api/telerik.blazor.components.diagramconnectioneditablepointsdescriptor)—configures connection point editing behavior, including enabling point editing and snap distance.

## Binding Data from Custom Models

You can map data from your existing model classes to the descriptor classes. This approach provides flexibility and allows you to integrate the Diagram with your application data.

The example below demonstrates how to:

* Use a custom model class (`DiagramEmployee`).
* Map the model data to `DiagramShapeDescriptor` and `DiagramConnectionDescriptor`.
* Set shape and connection properties such as color, text, and position.
* Use [rich content in the Shapes declaratively](https://www.telerik.com/blazor-ui/documentation/components/diagram/shapes#rich-content).

> caption Binding the Diagram to data from custom models

<demo metaUrl="client/diagram/data-bind/custom-models-2/" height="600"></demo>

## Direct Descriptor Initialization

You can also create the descriptor objects directly without mapping from custom models. This approach is useful when you don't have an existing data structure or prefer to define the Diagram data inline.

> caption Direct initialization of descriptor objects

<demo metaUrl="client/diagram/data-bind/direct-initialization-1/" height="620"></demo>

## See Also

* [Diagram Overview](https://www.telerik.com/blazor-ui/documentation/components/diagram/overview)
* [Diagram Shapes](https://www.telerik.com/blazor-ui/documentation/components/diagram/shapes)
* [Diagram Connections](https://www.telerik.com/blazor-ui/documentation/components/diagram/connections)
* [Diagram Layouts](https://www.telerik.com/blazor-ui/documentation/components/diagram/layouts)
