Search
Custom Item Types

You can create your own item types by deriving the DiagramNode and DiagramLink classes or their successors such as TableNode, ContainerNode and so on. This lets you add custom data fields to the diagram items, and implement custom visualization and interaction functionality.

Serialization

If you add custom fields to your item class, you will probably want their values saved when saving diagram files, and restored when loading files. To enable this, override the SaveToJson and LoadFromJson methods of the DiagramItem class, which let you implement JSON serialization. For XML serialization, you must implement the SaveToXml and LoadFromXml methods.

Clipboard operations

You must implement the Clone method in order to enable CopyToClipboard and PasteFromClipboard to work with your custom item type, If Clone is not implemented, you will get an instance of the base class created for the pasted item, and this could lead to an exception when the base class deserialization code tries to load the item state from a data stream created by the derived class. If your class has any custom fields, it must also implement the SaveToJson and LoadFromJson methods for proper serialization.

Rendering

If you need to provide custom rendering for your items, override the DrawLocal and DrawShadowLocal methods. They receive as an argument an object that implements the IGraphics interface, which provides methods for drawing vector graphics, text and images. MindFusion.Diagramming provides MauiGraphics, PdfGraphics and SvgGraphics implementations of that interface, which are used respectively when drawing on the screen, exporting to PDF and to SVG. That lets you use the same code regardless of where the item should draw itself.

User interaction

To let the user draw items from a custom class, set the Behavior property of the diagram view to Custom, and set the CustomNodeType or CustomLinkType property to the Type object that corresponds to your class. If you need to change how items handle user interaction while they are being initially created, implement the StartCreate, UpdateCreate and CompleteCreate methods. In order to change how items respond to user interaction while they are being modified, implement the StartModify, UpdateModify and CompleteModify methods.