Search
Creating and Deleting Items

Creating Items Programmatically

In order to add a new node or link to a diagram, create an instance of the item class by using the new operator and add it to the diagram's Nodes or Links collection. This works the same way for adding both items from your custom class or ones from the WpfDiagram predefined types.

There are several shortcut methods provided for creating instances of the predefined node and link types. The methods are members of the diagram's Factory object:

Drawing New Items

Users can draw diagram elements with the mouse. The Behavior property specifies what type of elements should be created when a user starts drawing. When a user starts drawing, an item is created and an initialization event is raised to let you customize the item appearance before showing it on the screen. The initialization events include ones such as InitializeNode, InitializeLink, and so on. While items are being drawn, the control raises validation events such as NodeCreating to let you validate the operation and prevent creating items at a specific location. When the user releases the mouse button, the item is added to the collection that contains items from the same type (for example Nodes) and an event is raised, for example NodeCreated.

Deleting Items

Call the Remove method of the Nodes or Links collection to delete an item from the diagram. The ClearAll method clears diagram contents by deleting all items. A shortcut for removing a link between two tables is provided by the BreakRelation method.

By default, deleting a node also removes its links. Set the AutoDeleteLinks property to false to prevent that, and disconnect the links instead.