Search
Diagram Class
Remarks See Also
 






Represents a flow diagram.

Namespace: MindFusion.Diagramming
Assembly: MindFusion.Diagramming

 Syntax

C#  Copy Code

public class Diagram : DiagramBase, IItemFactory

Visual Basic  Copy Code

Public Class Diagram
    Inherits DiagramBase
    Implements IItemFactory

 Remarks

An instance of the Diagram class represents a diagram document. A Diagram instance does not provide its own user interface. To display a diagram on a form, add a DiagramView instance to the form and set the view's Diagram property. A diagram can be displayed in more than one view.

A diagram can contain connected nodes and links. Nodes are instances of DiagramNode-derived classes. Nodes are stored in the Nodes collection. Links in MindFusion.Diagramming for .NET MAUI are instances of the DiagramLink class and are stored in the Links collection.

Managing Items

Items can be created by using the new operator and added to the diagram by means of the Add method of the Nodes or Links collection. Items are deleted by using the Remove method of the respective collection. There are shortcut methods provided by the diagram's Factory object that can be used to create an item and add it to the diagram with just one method call. Use the CreateTableNode, CreateShapeNode and CreateDiagramLink factory methods to create new items of the respective type.

Searching for a particular kind of items is done with the FindLink and FindNode methods, which look for an item that has a particular Tag, or FindLinkById and FindNodeById to find items by their Id. To get the item placed at a certain location, use the GetItemAt method.

Serialization

Use the SaveToXml and LoadFromXml methods to serialize a diagram into/from XML documents.

Controlling Users' Actions

Most aspects of user interaction are controlled by the DiagramView class.

Users actions can be validated by handling various events, fired while items are being created, modified or deleted.

The following properties control what kind of links users can create: AllowLinksRepeat, AllowSelfLoops, AllowUnanchoredLinks, AllowUnconnectedLinks.

The order in which items are hit-tested when clicking on them depends on the value of HitTestPriority. The LinkHitDistance property specifies the furthest distance from a link that a click would be still considered a hit.

Alignment

Items are aligned to a grid when AlignToGrid is enabled. To display the grid, set ShowGrid to true. The grid size and appearance can be customized via the GridSizeX, GridSizeY, GridColor and GridStyle properties.

If AutoAlignNodes is enabled, nodes are aligned to other nodes so that a pair of their vertical or horizontal sides become collinear. To specify the maximal distance at which nodes are aligned, set the AutoAlignDistance property. The pair of aligned nodes is indicated visually by drawing an alignment guide using the pen assigned to AlignmentGuidePen.

Links can also automatically snap to nodes when AutoSnapLinks is set. The maximal distance at which links will connect to a nearby node is set via AutoSnapDistance.

Appearance

The Diagram background area can be painted using a solid, gradient, texture or color brush, by setting the BackBrush property, and/or using an image specified by BackgroundImage and BackgroundImageAlign.

To further customize the diagram appearance, handle the DrawBackground event to render custom background graphics, or the DrawForeground event to render custom foreground graphics.

Lanes

The lane grid lets you emphasize the relationship between a group of diagram items by displaying them in a distinct lane or cell within the grid. Use the EnableLanes property to display a background grid of lanes, optionally divided into cells. The grid can be set up using the LaneGrid property.

Text Formatting

Use TextFormat and TextColor to specify alignment and color of the text for all diagram items. EnableStyledText allows using HTML-like tags to format item's text. PolygonalTextLayout allows laying text out inside non-rectangular node shapes.

Tweaks

  • SelectionOnTop specifies whether selected items should be painted on top of other items.
  • MergeThreshold specifies how closely to each other adjacent link points should be placed in order to merge link segments.

Default Item Properties

Many properties of the Diagram class provide initial values for the properties of new items.

 Inheritance Hierarchy

System.Object
    Microsoft.Maui.Controls.BindableObject
        Microsoft.Maui.Controls.Element
            Microsoft.Maui.Controls.NavigableElement
                Microsoft.Maui.Controls.VisualElement
                    Microsoft.Maui.Controls.View
                        Microsoft.Maui.Controls.Layout
                            Microsoft.Maui.Controls.AbsoluteLayout
                                MindFusion.Diagramming.DiagramBase
                                    MindFusion.Diagramming.Diagram

 See Also