Class SfDiagram
Keeps Connectors in sync with the JavaScript-side diagram. See the remarks on
SfDiagram's Nodes counterpart (SfDiagram.Nodes.cs) for the general approach.
Implements
IDrawable
IAbsoluteLayout
ILayout
IView
IElement
ITransform
IContainer
ISafeAreaView
IPadding
ICrossPlatformLayout
IVisualTreeElement
Assembly: Syncfusion.Maui.Diagram.dll
Syntax
public class SfDiagram : SfView, IDrawableLayout, IDrawable, IAbsoluteLayout, ILayout, IView, IElement, ITransform, IContainer, IList<IView>, ICollection<IView>, IEnumerable<IView>, IEnumerable, ISafeAreaView, IPadding, ICrossPlatformLayout, IVisualTreeElement, IDisposable
Constructors
SfDiagram()
Initializes a new instance of the SfDiagram class.
Declaration
Fields
ConnectorDefaultsProperty
Declaration
public static readonly BindableProperty ConnectorDefaultsProperty
Field Value
ConnectorsProperty
Declaration
public static readonly BindableProperty ConnectorsProperty
Field Value
DataSourceSettingsProperty
Declaration
public static readonly BindableProperty DataSourceSettingsProperty
Field Value
HeightProperty
Identifies the Height bindable property.
Declaration
public static readonly BindableProperty HeightProperty
Field Value
IdProperty
Identifies the Id bindable property.
Declaration
public static readonly BindableProperty IdProperty
Field Value
LayoutProperty
Identifies the Layout bindable property.
Declaration
public static readonly BindableProperty LayoutProperty
Field Value
NodeDefaultsProperty
Declaration
public static readonly BindableProperty NodeDefaultsProperty
Field Value
NodesProperty
Identifies the Nodes bindable property.
Declaration
public static readonly BindableProperty NodesProperty
Field Value
WidthProperty
Identifies the Width bindable property.
Declaration
public static readonly BindableProperty WidthProperty
Field Value
Properties
ConnectorDefaults
Gets or sets the default routing/styling of data-bound connectors.
Declaration
public ConnectorDefaults? ConnectorDefaults { get; set; }
Property Value
Connectors
Gets or sets the diagram's connectors.
Declaration
public ObservableCollection<Connector> Connectors { get; set; }
Property Value
DataSourceSettings
Gets or sets the data source an organizational chart is generated from. Setting this while manual
nodes exist raises InvalidOperationException (mixing is out of scope).
Declaration
public DataSourceSettings? DataSourceSettings { get; set; }
Property Value
Height
Gets or sets the requested height of the diagram in device-independent units.
Defaults to -1, which lets the MAUI layout system size the control to fit the available space.
Setting this property updates Microsoft.Maui.Controls.VisualElement.HeightRequest so the MAUI layout engine
uses the value; the inherited read-only Microsoft.Maui.Controls.VisualElement.Height continues to report
the actual arranged height after layout.
Declaration
public double Height { get; set; }
Property Value
Id
Gets or sets the diagram's identifier. Assigned automatically when left null.
Declaration
public string? Id { get; set; }
Property Value
Layout
Gets or sets the automatic-arrangement configuration applied to Nodes/Connectors.
Defaults to a DiagramLayout with None (manual positioning).
Mutating this instance's properties in place — or assigning a new DiagramLayout — re-runs
the layout once the diagram is ready.
Declaration
public DiagramLayout Layout { get; set; }
Property Value
NodeDefaults
Gets or sets the default size/shape/styling of data-bound nodes.
Declaration
public NodeDefaults? NodeDefaults { get; set; }
Property Value
Nodes
Gets or sets the diagram's nodes.
Declaration
public ObservableCollection<Node> Nodes { get; set; }
Property Value
Width
Gets or sets the requested width of the diagram in device-independent units.
Defaults to -1, which lets the MAUI layout system size the control to fit the available space.
Setting this property updates Microsoft.Maui.Controls.VisualElement.WidthRequest so the MAUI layout engine
uses the value; the inherited read-only Microsoft.Maui.Controls.VisualElement.Width continues to report
the actual arranged width after layout.
Declaration
public double Width { get; set; }
Property Value
Methods
Add(Connector)
Connector counterpart of Add(Node). Adds connector to the EJ2
canvas only, leaving Connectors untouched.
Declaration
public Task Add(Connector connector)
Parameters
Returns
Add(Node)
Adds node to the EJ2 canvas without putting it in Nodes.
Distinct from Nodes.Add: this method only mutates the EJ2 canvas
(the "remote" side) and does NOT make node part of the diagram's authoritative
model. Use this for cases where the application is rendering nodes it does not own in the managed
Nodes collection. To round-trip a node across both sides, use the standard
Nodes.Add(node) instead.
Declaration
public Task Add(Node node)
Parameters
| Type |
Name |
Description |
| Node |
node |
|
Returns
CanRedoAsync()
Gets whether a redo is currently available. Always false before Created fires.
Declaration
public Task<bool> CanRedoAsync()
Returns
CanUndoAsync()
Gets whether an undo is currently available. Always false before Created fires.
Declaration
public Task<bool> CanUndoAsync()
Returns
Copy()
Copies the diagram's current selection to the diagram's clipboard and returns the clipboard
contents as a JSON string (a { nodes, connectors } bag in EJ2's wire shape). Returns
null when called before Created has fired, or when EJ2's
own copy returns an empty result.
Declaration
public Task<string?> Copy()
Returns
Cut()
Cuts the diagram's current selection to the diagram's clipboard. Operates on whatever node and
connector set is currently selected in the diagram's UI — typically selected by
Syncfusion.Maui.Diagram.SfDiagram.SelectAll first, or by an earlier Selection-{node|connector}.id set in code.
A no-op until Created has fired.
Declaration
Returns
Dispose()
Declaration
Dispose(bool)
Releases the diagram's WebView, JavaScript bridge, and event subscriptions.
Declaration
protected virtual void Dispose(bool disposing)
Parameters
| Type |
Name |
Description |
| bool |
disposing |
|
DoLayoutAsync(CancellationToken)
Forces a layout pass and completes once the layout (and animation, when enabled) has finished.
Faults with InvalidOperationException if the JavaScript layout throws; the cancellation
token only stops the waiting.
Declaration
public Task DoLayoutAsync(CancellationToken cancellationToken = default)
Parameters
Returns
ExportDiagram(DiagramExportOptions?)
Exports the diagram and returns the result as a string: a data URI
("data:image/png;base64,...", etc.) for Png/
Jpg/Bmp, or raw
<svg> markup for Svg. Returns
null if called before Created fires. This control never
writes the result to disk itself — decoding/saving/sharing it is left to the caller.
Declaration
public Task<string?> ExportDiagram(DiagramExportOptions? options = null)
Parameters
| Type |
Name |
Description |
| DiagramExportOptions |
options |
Export settings, or null (the default) to use every EJ2 default: PNG,
Content, 25-unit margins on every side.
|
Returns
FitToPage()
Zooms/pans so that every node and connector fits within the viewport. A no-op until
Created has fired.
Declaration
Returns
LoadDiagram(string)
Replaces Nodes and Connectors with the diagram reconstructed from
json (as produced by Syncfusion.Maui.Diagram.SfDiagram.GetDiagramState(System.Boolean)). Whatever is currently
in Nodes/Connectors is cleared first — this replaces the diagram, it
doesn't merge into it. Works whether or not Created has fired yet, the same way
populating Nodes/Connectors directly does.
Declaration
public void LoadDiagram(string json)
Parameters
| Type |
Name |
Description |
| string |
json |
|
Exceptions
OnBindingContextChanged()
Declaration
protected override void OnBindingContextChanged()
Overrides
Pan(double, double, Point?)
Sets the diagram viewport's horizontal/vertical scroll offsets in diagram units.
focusedPoint, when non-null, sets the viewport's centre after the pan.
Declaration
public Task Pan(double horizontalOffset, double verticalOffset, Point? focusedPoint = null)
Parameters
| Type |
Name |
Description |
| double |
horizontalOffset |
|
| double |
verticalOffset |
|
| Point? |
focusedPoint |
|
Returns
Paste(IEnumerable<DiagramElement>?)
Pastes from the diagram's clipboard onto the diagram. Pass elements to paste
an explicit batch of nodes/connectors from your own collection; pass null (the
default) to paste whatever the diagram's current clipboard holds (the contents most recently
produced by Cut() or Copy()).
Declaration
public Task Paste(IEnumerable<DiagramElement>? elements = null)
Parameters
Returns
Print(DiagramExportOptions?)
Prints the diagram. A no-op until Created has fired.
Declaration
public Task Print(DiagramExportOptions? options = null)
Parameters
| Type |
Name |
Description |
| DiagramExportOptions |
options |
Export settings applied before printing, or null (the default) to use every EJ2
default.
|
Returns
Redo()
Redoes the last undone action. A no-op until Created has fired or if there is
nothing to redo. Ctrl+Y/Ctrl+Shift+Z also trigger this from within the diagram's own
UI once it has focus; see the remarks on Undo().
Declaration
Returns
Remove(Connector)
Connector counterpart of Remove(Node). Removes connector from the
EJ2 canvas only, leaving Connectors untouched.
Declaration
public Task Remove(Connector connector)
Parameters
Returns
Remove(Node)
Removes node from the EJ2 canvas. Distinct from
Nodes.Remove: this method only mutates the EJ2 canvas and does
NOT remove node from Nodes.
Declaration
public Task Remove(Node node)
Parameters
| Type |
Name |
Description |
| Node |
node |
|
Returns
SaveDiagram()
Serializes this diagram control to a JSON string — the same shape
Syncfusion.Maui.Diagram.SfDiagram.GetDiagramState(System.Boolean) produces, the same string LoadDiagram(string)
can later round-trip back into this control.
Declaration
public string SaveDiagram()
Returns
ScaleAsync(Connector, double, double, Point)
Declaration
public Task ScaleAsync(Connector connector, double sx, double sy, Point pivot)
Parameters
Returns
ScaleAsync(Node, double, double, Point)
Resizes node by multiplying its width by sx and its height
by sy around pivot in diagram units. EJ2 echoes the
resulting geometry back via its existing sizeChange hook → SizeChanged.
Declaration
public Task ScaleAsync(Node node, double sx, double sy, Point pivot)
Parameters
Returns
Undo()
Undoes the last undoable action (adding/removing/moving/resizing a Node or
Connector, etc.). A no-op until Created has fired or if there is
nothing to undo. Backed by the EJ2 UndoRedo module, which this control injects
automatically — no separate opt-in is required. Ctrl+Z also triggers this from within the
diagram's own UI once it has focus, since EJ2 wires that shortcut up itself once the module is injected.
Declaration
Returns
Zoom(double, Point?)
Multiplies the current zoom level by factor (e.g. 1.25 for "zoom in 25%",
0.8 for "zoom out 20%"). Pass focusedPoint to zoom centered on a
specific viewport point rather than the diagram's geometric centre.
Declaration
public Task Zoom(double factor, Point? focusedPoint = null)
Parameters
| Type |
Name |
Description |
| double |
factor |
|
| Point? |
focusedPoint |
|
Returns
Events
CollectionChanged
Raised whenever a Node or Connector is added to, or removed from, this
diagram — whether that happened because application code changed Nodes/Connectors
directly, or because of something the user did in the WebView (a SymbolPalette
drop, an interactively-drawn connector, a delete/cut, or an undo/redo of any of those — see
DiagramCollectionChangedEventArgs's remarks). One event, either collection, any cause.
Declaration
public event EventHandler<DiagramCollectionChangedEventArgs>? CollectionChanged
Event Type
ConnectionChanged
Raised after a Connector's source and/or target endpoint finishes attaching to,
detaching from, or being re-routed between nodes/ports in the WebView. Fires once per
EJ2-side connectionChange "Changed" state with both pre/post values on the
DiagramConnectorConnectionChangedEventArgs.
Declaration
public event EventHandler<DiagramConnectorConnectionChangedEventArgs>? ConnectionChanged
Event Type
Created
Raised once the JavaScript-side ej.diagrams.Diagram instance has been created and is ready
to receive nodes and connectors. Nodes/connectors added to Nodes/Connectors
before this fires are not lost — they're included in the startup snapshot — so waiting for this
event is optional, not required, before populating the diagram.
Declaration
public event EventHandler? Created
Event Type
ExpandStateChange
Raised exactly once per expand/collapse state change, with the cause.
Declaration
public event EventHandler<ExpandStateChangeEventArgs>? ExpandStateChange
Event Type
JavaScriptError
Raised when a call into the hosted page's JavaScript throws instead of completing normally — for
example, an environment problem like ej2.min.js failing to load, or a malformed payload.
Without a subscriber this is still visible via WriteLine(string),
but a failure here is otherwise the reason the diagram silently doesn't render, so production apps
should consider handling it (e.g. logging it through their own diagnostics).
Declaration
public event EventHandler<DiagramJavaScriptErrorEventArgs>? JavaScriptError
Event Type
LayoutUpdated
Raised after a layout pass completes (after animation when enabled) — exactly once per flush.
Declaration
public event EventHandler<LayoutUpdatedEventArgs>? LayoutUpdated
Event Type
LayoutValidationFailed
Raised before LayoutUpdated when the flushed data had repairable problems.
Declaration
public event EventHandler<LayoutValidationEventArgs>? LayoutValidationFailed
Event Type
PositionChanged
Declaration
public event EventHandler<DiagramNodePositionChangedEventArgs>? PositionChanged
Event Type
RotationChanged
Raised after a node finishes being rotated in the WebView.
Declaration
public event EventHandler<DiagramNodeRotationChangedEventArgs>? RotationChanged
Event Type
SelectionChanged
Raised after the user selects or deselects nodes or connectors in the diagram's UI.
Declaration
public event EventHandler<DiagramSelectionChangedEventArgs>? SelectionChanged
Event Type
SizeChanged
Raised after a node finishes being resized in the WebView. Deliberately hides
Microsoft.Maui.Controls.VisualElement.SizeChanged — the base control-layout-resize event every
Microsoft.Maui.Controls.VisualElement already has — with the new
keyword below, since the name was requested for this node-level event specifically. Existing code
that wants the base control's own arranged-size event still can, by subscribing through a
Microsoft.Maui.Controls.VisualElement-typed reference (e.g. ((VisualElement)diagram).SizeChanged += ...)
instead of a SfDiagram-typed one.
Declaration
public event EventHandler<DiagramNodeSizeChangedEventArgs>? SizeChanged
Event Type
SourcePointChanged
Declaration
public event EventHandler<DiagramConnectorSourcePointChangedEventArgs>? SourcePointChanged
Event Type
TargetPointChanged
Declaration
public event EventHandler<DiagramConnectorTargetPointChangedEventArgs>? TargetPointChanged
Event Type
TextEdited
Raised after a double-tap/double-click label edit is committed in the WebView (the user typed new
text into a node's or connector's annotation and then unfocused it), once the corresponding
Content has already been updated on the native side. Added as a diagnostic
hook: subscribing to this (with a breakpoint, a WriteLine(string),
or a bound label) confirms whether an edit is actually making it from the WebView back to the native
model at all, without needing a JavaScript debugger attached to the hosted page.
Declaration
public event EventHandler<DiagramTextEditedEventArgs>? TextEdited
Event Type
Implements
Microsoft.Maui.Graphics.IDrawable
Microsoft.Maui.IAbsoluteLayout
Microsoft.Maui.ILayout
Microsoft.Maui.IView
Microsoft.Maui.IElement
Microsoft.Maui.ITransform
Microsoft.Maui.IContainer
Microsoft.Maui.ISafeAreaView
Microsoft.Maui.IPadding
Microsoft.Maui.ICrossPlatformLayout
Microsoft.Maui.IVisualTreeElement