menu

Blazor

  • Code Examples
  • Upgrade Guide
  • User Guide
  • Demos
  • Support
  • Forums
  • Download
Class DiagramObjectCollection<T> - Blazor API Reference | Syncfusion

    Show / Hide Table of Contents

    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.

    Inheritance
    System.Object
    DiagramObjectCollection<T>
    Namespace: Syncfusion.Blazor.Diagram
    Assembly: Syncfusion.Blazor.dll
    Syntax
    public class DiagramObjectCollection<T> : ObservableCollection<T>
    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
    System.Collections.Generic.IEnumerable<T> collection

    An System.Collections.Generic.IEnumerable<> 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
    System.Threading.Tasks.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()
    Back to top Generated by DocFX
    Copyright © 2001 - 2025 Syncfusion Inc. All Rights Reserved