Skip to content

Mermaid Diagrams | Theming

The diagram appearance is controlled by a DiagramTheme set on the Theme property. Four themes are included and you can create your own by subclassing DiagramTheme.

ThemeBackgroundNodesEdgesBest For
DefaultThemeWhiteBlue fill, white textGrayLight mode apps
DarkThemeDark navyDeep blue fill, red strokeRedDark mode apps
ForestThemeLight greenGreen fill, white textGreenNature/organic UIs
NeutralThemeLight grayGray fill, dark textDark grayMinimal/document style
control.Theme = new DarkTheme();
<diagrams:MermaidDiagramControl
DiagramText="{Binding MermaidText}">
<diagrams:MermaidDiagramControl.Theme>
<theming:ForestTheme />
</diagrams:MermaidDiagramControl.Theme>
</diagrams:MermaidDiagramControl>

Subclass DiagramTheme and override all abstract members:

using Shiny.Maui.MermaidDiagrams.Theming;
public sealed class MyCustomTheme : DiagramTheme
{
public override Color BackgroundColor => Color.FromArgb("#fafafa");
public override Color TextColor => Color.FromArgb("#222222");
public override float FontSize => 13f;
public override NodeRenderStyle DefaultNodeStyle => new()
{
FillColor = Color.FromArgb("#6c5ce7"),
StrokeColor = Color.FromArgb("#5a4bd1"),
TextColor = Colors.White,
StrokeWidth = 2,
CornerRadius = 8
};
public override EdgeRenderStyle DefaultEdgeStyle => new()
{
StrokeColor = Color.FromArgb("#636e72"),
StrokeWidth = 1.5f,
LabelBackgroundColor = Color.FromArgb("#fafafa"),
LabelTextColor = Color.FromArgb("#222222")
};
public override SubgraphRenderStyle DefaultSubgraphStyle => new()
{
FillColor = Color.FromArgb("#f0f0f5"),
StrokeColor = Color.FromArgb("#6c5ce7"),
TitleColor = Color.FromArgb("#6c5ce7"),
StrokeWidth = 1.5f,
CornerRadius = 10
};
}
PropertyTypeDefaultDescription
FillColorColorBackground fill color
StrokeColorColorBorder stroke color
TextColorColorLabel text color
StrokeWidthfloat2Border width
CornerRadiusfloat4Corner radius for rectangular shapes
PropertyTypeDefaultDescription
StrokeColorColorLine color
StrokeWidthfloat2Line width
LabelBackgroundColorColorBackground behind edge labels
LabelTextColorColorEdge label text color
PropertyTypeDefaultDescription
FillColorColorSubgraph background fill
StrokeColorColorSubgraph border color
TitleColorColorSubgraph title text color
StrokeWidthfloat1.5Border width
CornerRadiusfloat8Corner radius of subgraph box

Override GetNodeStyle(int index) to vary node colors by index position:

public override NodeRenderStyle GetNodeStyle(int index) =>
(index % 3) switch
{
0 => new NodeRenderStyle
{
FillColor = Colors.SteelBlue,
StrokeColor = Colors.DarkSlateBlue,
TextColor = Colors.White
},
1 => new NodeRenderStyle
{
FillColor = Colors.MediumSeaGreen,
StrokeColor = Colors.SeaGreen,
TextColor = Colors.White
},
_ => DefaultNodeStyle
};