Skip to content

Mermaid Diagrams | Control Properties

The MermaidDiagramControl is a ContentView that parses Mermaid flowchart text and renders it using MAUI Graphics.

<diagrams:MermaidDiagramControl
DiagramText="{Binding MermaidText}"
Theme="{Binding SelectedTheme}"
ZoomLevel="{Binding Zoom}"
ParseError="{Binding Error, Mode=OneWayToSource}"
AllowPanning="True"
AllowZooming="True" />
PropertyTypeDefaultDescription
DiagramTextstring""Mermaid flowchart syntax to parse and render
ThemeDiagramThemeDefaultThemeTheme controlling colors, fonts, and styles
ZoomLevelfloat1fZoom scale factor (0.1–5.0)
ParseErrorstring?nullError message when parsing fails, null on success
DiagramLayoutOptionsDiagramLayoutOptionsdefaultsLayout spacing and sizing options
AllowPanningbooltrueEnable pan gesture to scroll the diagram
AllowZoomingbooltrueEnable pinch-to-zoom gesture

Control the spacing and sizing of diagram elements via DiagramLayoutOptions:

control.DiagramLayoutOptions = new DiagramLayoutOptions
{
NodeWidth = 150,
NodeHeight = 50,
HorizontalSpacing = 60,
VerticalSpacing = 80,
SubgraphPadding = 30,
FontSize = 14,
Margin = 40
};
PropertyTypeDefaultDescription
NodeWidthfloat150Width of each node
NodeHeightfloat50Height of each node
HorizontalSpacingfloat60Horizontal gap between nodes
VerticalSpacingfloat80Vertical gap between layers
SubgraphPaddingfloat30Padding inside subgraph borders
FontSizefloat14Font size for node and edge labels
Marginfloat40Outer margin around the entire diagram

When parsing fails, ParseError is set with the error message and the diagram clears. Bind to this property to show validation feedback in a live editor:

control.SetBinding(
MermaidDiagramControl.ParseErrorProperty,
static (MyViewModel vm) => vm.ErrorMessage,
mode: BindingMode.OneWayToSource);
  • Pan — Drag to scroll the diagram within the view. Enabled via AllowPanning.
  • Pinch-to-zoom — Pinch gesture scales the diagram between 0.1x and 5x. Updates ZoomLevel (two-way).

Both gestures can be disabled independently for scenarios like embedded read-only diagrams.

You can also parse and layout diagrams without the control:

using Shiny.Maui.MermaidDiagrams.Parsing;
using Shiny.Maui.MermaidDiagrams.Layout;
var model = MermaidParser.Parse("graph TD\n A --> B --> C");
var engine = new SugiyamaLayoutEngine();
var result = engine.Layout(model, new DiagramLayoutOptions());
// result.Nodes — positioned nodes
// result.Edges — routed edge paths
// result.Subgraphs — positioned subgraph bounds
// result.TotalWidth / result.TotalHeight — overall diagram size