Class StyledNodeRendererBase
- Namespace
- FlowGraph.Avalonia.Rendering.NodeRenderers
- Assembly
- FlowGraph.Avalonia.dll
Base class for styled node renderers with icon and label support. Provides customizable colors, icons (text or geometry), and inline editing.
Override the abstract properties to customize appearance: - DefaultLabel: Default text when no label is set - GetNodeBackground(ThemeResources), GetNodeBorder(ThemeResources): Node colors - GetIconForeground(ThemeResources), GetTextForeground(ThemeResources): Text/icon colors
For icons, override ONE of: - IconText: Simple text icon (e.g., ">", "O", "?") - IconGeometry: Vector path for scalable icons (compatible with any icon library)
// Get path data from any icon library (Lucide, Material, etc.)
protected override Geometry? IconGeometry =>
Geometry.Parse("M5 12h14M12 5l7 7-7 7"); // arrow-right
public abstract class StyledNodeRendererBase : DefaultNodeRenderer, IEditableNodeRenderer, INodeRenderer
- Inheritance
-
StyledNodeRendererBase
- Implements
- Derived
- Inherited Members
Fields
IconTag
Tag used to identify the icon element.
protected const string IconTag = "NodeIcon"
Field Value
LabelTag
Tag used to identify the label TextBlock.
protected const string LabelTag = "NodeLabel"
Field Value
Properties
DefaultLabel
Gets the default label when no label or data is set.
protected abstract string DefaultLabel { get; }
Property Value
IconGeometry
Gets the geometry for a vector icon. This takes precedence over IconText.
Use this to integrate with any icon library (Lucide, Material, FontAwesome, etc.)
by providing the icon's path data.
// Simple arrow icon
protected override Geometry? IconGeometry =>
Geometry.Parse("M5 12h14M12 5l7 7-7 7");
// Or use a static geometry for better performance
private static readonly Geometry _icon = Geometry.Parse("M5 12h14");
protected override Geometry? IconGeometry => _icon;
protected virtual Geometry? IconGeometry { get; }
Property Value
- Geometry
IconSize
Gets the icon size in canvas units (before scaling). Default is 16.
protected virtual double IconSize { get; }
Property Value
IconText
Gets the text icon to display (e.g., ">", "O", "?"). Override IconGeometry instead for vector icons. Default is null (no text icon).
protected virtual string? IconText { get; }
Property Value
Methods
BeginEdit(Control, Node, NodeRenderContext, Action<string>, Action)
Enters edit mode - replaces the label TextBlock with a TextBox.
public override void BeginEdit(Control visual, Node node, NodeRenderContext context, Action<string> onCommit, Action onCancel)
Parameters
visualControlnodeNodecontextNodeRenderContextonCommitAction<string>onCancelAction
CreateIconElement(NodeRenderContext)
Creates the icon element based on IconGeometry or IconText.
protected virtual Control? CreateIconElement(NodeRenderContext context)
Parameters
contextNodeRenderContext
Returns
- Control
CreateNodeContent(Node, NodeRenderContext)
Creates the content inside the node. Override to customize.
protected override Control CreateNodeContent(Node node, NodeRenderContext context)
Parameters
nodeNodecontextNodeRenderContext
Returns
- Control
CreateNodeVisual(Node, NodeRenderContext)
Creates the visual representation for a node.
public override Control CreateNodeVisual(Node node, NodeRenderContext context)
Parameters
nodeNodeThe node data to render.
contextNodeRenderContextThe rendering context with theme, scale, and settings.
Returns
- Control
A Control representing the node visual.
EndEdit(Control, Node, NodeRenderContext)
Exits edit mode - removes the TextBox and shows the label.
public override void EndEdit(Control visual, Node node, NodeRenderContext context)
Parameters
visualControlnodeNodecontextNodeRenderContext
FindStackPanelContent(Control)
Finds the StackPanel content in the node visual.
protected StackPanel? FindStackPanelContent(Control visual)
Parameters
visualControl
Returns
- StackPanel
GetDisplayText(Node)
Gets the display text for the node. Override to customize.
protected override string GetDisplayText(Node node)
Parameters
nodeNode
Returns
GetEditableText(Node)
Gets the text to edit. Override to customize.
protected override string GetEditableText(Node node)
Parameters
nodeNode
Returns
GetIconForeground(ThemeResources)
Gets the icon foreground brush for this node type.
protected abstract IBrush GetIconForeground(ThemeResources theme)
Parameters
themeThemeResources
Returns
- IBrush
GetNodeBackground(ThemeResources)
Gets the background brush for this node type.
protected abstract IBrush GetNodeBackground(ThemeResources theme)
Parameters
themeThemeResources
Returns
- IBrush
GetNodeBorder(ThemeResources)
Gets the border brush for this node type (when not selected).
protected abstract IBrush GetNodeBorder(ThemeResources theme)
Parameters
themeThemeResources
Returns
- IBrush
GetTextForeground(ThemeResources)
Gets the text foreground brush for this node type.
protected abstract IBrush GetTextForeground(ThemeResources theme)
Parameters
themeThemeResources
Returns
- IBrush
IsEditing(Control)
Gets whether the node is currently in edit mode.
public override bool IsEditing(Control visual)
Parameters
visualControl
Returns
UpdateSelection(Control, Node, NodeRenderContext)
Updates the visual state when selection changes.
public override void UpdateSelection(Control visual, Node node, NodeRenderContext context)
Parameters
visualControlThe node's visual control.
nodeNodeThe node data.
contextNodeRenderContextThe rendering context.