Node count when creating nodes with stencil dragging

How to achieve the following functions when using stencil?

For example, I am using stencil to create a new node on the diagram by dragging, if this is the third node I created by dragging from stencil, set the ID of this node to "3".


3 Replies

DT Deepa Thiruppathy Syncfusion Team June 1, 2022 10:34 AM UTC

Hi Tealer,


Requirement: How to calculate and update node’s count when node is drag and dropped from stencil


We have achieved this requirement by using ItemAddedEvent and its arguments. When node is drag and dropped from stencil, ItemSource argument of event will be updated as Stencil.


Code snippet:

//item added event.

(diagram.Info as IGraphInfo).ItemAdded += MainWindow_ItemAdded;

//To hold node count.

int nodeCount = 0;

 

private void MainWindow_ItemAdded(object sender, ItemAddedEventArgs args)

{

    //checking added item is node and whether it is added from stencil

    if (args.Item is NodeViewModel && args.ItemSource == ItemSource.Stencil)

    {

        nodeCount += 1;

        NodeViewModel node = args.Item as NodeViewModel;

        node.ID = nodeCount.ToString();

        //Initialize the AnnotationCollection

        node.Annotations = new ObservableCollection<IAnnotation>()

        {

            //adding node ID value as annotation.

            new AnnotationEditorViewModel()

            {

                Content=node.ID,

            }

        };

    }

}


Sample link: https://www.syncfusion.com/downloads/support/directtrac/general/ze/StencilDiagramElements961557993


Regards,

Deepa Thiruppathy



TE tealer June 7, 2022 09:04 AM UTC

Thanks for solving my problem, it works great.



DT Deepa Thiruppathy Syncfusion Team June 8, 2022 06:15 AM UTC

You are welcome. Please let us know if you require any further assistance.


Loader.
Up arrow icon