Class DiagramObjectCollection<T>
Represents a dynamic data collection that provides notifications when nodes, connectors, annotations, or ports are added, removed, or when the entire list is refreshed.
Inherited Members
Namespace: Syncfusion.Blazor.Diagram
Assembly: Syncfusion.Blazor.Diagram.dll
Syntax
public class DiagramObjectCollection<T> : ObservableCollection<T>, IList<T>, ICollection<T>, IList, ICollection, IReadOnlyList<T>, IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable, INotifyCollectionChanged, INotifyPropertyChanged
Type Parameters
| Name | Description |
|---|---|
| T | Specifies the type of elements in the collection. |
Remarks
This collection is observable and raises change notifications when items are added, removed, or the collection is otherwise modified.
Examples
The following example demonstrates how to create a new DiagramObjectCollection<T>.
// Create a new instance of DiagramObjectCollection
DiagramObjectCollection collection = new DiagramObjectCollection<Node>();
Constructors
DiagramObjectCollection()
Initializes a new instance of the HistoryEntry class.
Declaration
public DiagramObjectCollection()
DiagramObjectCollection(IEnumerable<T>)
Initializes a new instance of the DiagramObjectCollection<T> class using the specified collection.
Declaration
public DiagramObjectCollection(IEnumerable<T> collection)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<T> | collection | An IEnumerable<T> whose elements are copied to the new collection. |
Methods
AddAsync(T)
Asynchronously adds an item to the diagram object collection. This operation is applicable only to ports and annotations.
Declaration
public Task AddAsync(T item)
Parameters
| Type | Name | Description |
|---|---|---|
| T | item | The item to add, which must be of type Annotation or Port. |
Returns
| Type | Description |
|---|---|
| Task | A task representing the asynchronous operation, with the added diagram object upon completion. |
Remarks
This method is designed to add ports and annotations to the collection, initializing them as needed.
Examples
// Method for adding labels at runtime
public async void AddLabel()
{
ShapeAnnotation annotation = new ShapeAnnotation { Content = "Annotation" };
await (diagram.Nodes[0].Annotations as DiagramObjectCollection<ShapeAnnotation>).AddAsync(annotation);
}
ClearItems()
Removes all the elements from the diagram object collection.
Declaration
protected override void ClearItems()
Overrides
RemoveItem(int)
Removes the item at the specified index from the collection. This method is invoked when an item is removed through Remove(), RemoveAt(), or other internal collection operations.
Declaration
protected override void RemoveItem(int index)
Parameters
| Type | Name | Description |
|---|---|---|
| int | index | The zero-based index of the item to remove. |