We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

From Stencil to INode

How do you get into the base Node interface for when you drop a Symbol from the Stencil to the SfDiagram?  I need to implement an INode so that I have full control over the contents, specifically in terms of creating ports.

3 Replies

RA Ranjitha Amirthalingam Syncfusion Team September 28, 2015 12:24 PM UTC

Hi Steven,

Thanks for contacting Syncfusion Support.

Requirement: Need to add Port for the dropped Node from the Stencil.

We have provided support for ItemAdded event in SfDiagram. This event will get invoked when Symbol dropped to SfDiagram from Stencil. ItemAddedEventsargs will help to identify the dropped Node. We have provided code example and sample to achieve your requirement. Please refer to the code example and sample as below.

Code Example:

void MainWindow_ItemAdded(object sender, ItemAddedEventArgs args)

        {

            if (args.ItemSource == ItemSource.Stencil)

            {

                var dropedItem = args.Item as INode;


                if (dropedItem != null)

                {

                    INodePort port1 = addPort(dropedItem, 0.5, 0.5);

                    dropedItem.Ports = new ObservableCollection<INodePort>()

                         {

                            port1

                         };


                }


            }


        }


private INodePort addPort(INode node, double p1, double p2)

        {

            NodePort v = new NodePort()

            {

                Width = 11,

                Height = 11,

                NodeOffsetX = p1,

                NodeOffsetY = p2,

                Node=node,

                Shape = new EllipseGeometry() { RadiusX = 10, RadiusY = 10 },

                ShapeStyle = this.Resources["portstyle"] as Style,

              

            };

            return v;
        }



Sample Link: DroppedNode_with_ports


Regards,
Ranjitha A.


SB Steven Brodhead September 28, 2015 09:14 PM UTC

ItemAdded is in SfDiagram.Info?  Thanks!  I would have never found it there, and would have probably ended up doing something horrifying like listening to the node collection for changes.

This helps a lot!


RA Ranjitha Amirthalingam Syncfusion Team September 29, 2015 06:12 AM UTC

Hi Steven,

Thanks for your update.


Regards,
Ranjitha A.

Loader.
Live Chat Icon For mobile
Up arrow icon