Table of Contents

Class DefaultNodeRenderer

Namespace
FlowGraph.Avalonia.Rendering.NodeRenderers
Assembly
FlowGraph.Avalonia.dll

Default node renderer that creates a standard bordered box with text. Supports inline label editing via IEditableNodeRenderer.

public class DefaultNodeRenderer : IEditableNodeRenderer, INodeRenderer
Inheritance
DefaultNodeRenderer
Implements
Derived
Inherited Members

Methods

BeginEdit(Control, Node, NodeRenderContext, Action<string>, Action)

Enters edit mode - replaces the label TextBlock with a TextBox.

public virtual void BeginEdit(Control visual, Node node, NodeRenderContext context, Action<string> onCommit, Action onCancel)

Parameters

visual Control
node Node
context NodeRenderContext
onCommit Action<string>
onCancel Action

CreateNodeContent(Node, NodeRenderContext)

Creates the content inside the node. Override to customize.

protected virtual Control CreateNodeContent(Node node, NodeRenderContext context)

Parameters

node Node
context NodeRenderContext

Returns

Control

CreateNodeVisual(Node, NodeRenderContext)

Creates the visual representation for a node.

public virtual Control CreateNodeVisual(Node node, NodeRenderContext context)

Parameters

node Node

The node data to render.

context NodeRenderContext

The 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 virtual void EndEdit(Control visual, Node node, NodeRenderContext context)

Parameters

visual Control
node Node
context NodeRenderContext

FindContentPanel(Control)

Finds the content panel in the node visual.

protected Grid? FindContentPanel(Control visual)

Parameters

visual Control

Returns

Grid

FindLabelTextBlock(Grid)

Finds the label TextBlock in the content panel.

protected TextBlock? FindLabelTextBlock(Grid contentPanel)

Parameters

contentPanel Grid

Returns

TextBlock

GetBorderBrush(Node, ThemeResources)

Gets the appropriate border brush based on node state. Priority: Selected > Highlighted > Normal

protected virtual IBrush GetBorderBrush(Node node, ThemeResources theme)

Parameters

node Node
theme ThemeResources

Returns

IBrush

GetBorderThickness(Node)

Gets the appropriate border thickness based on node state.

protected virtual Thickness GetBorderThickness(Node node)

Parameters

node Node

Returns

Thickness

GetDisplayText(Node)

Gets the display text for the node. Override to customize.

protected virtual string GetDisplayText(Node node)

Parameters

node Node

Returns

string

GetEditableText(Node)

Gets the text to edit. Override to customize.

protected virtual string GetEditableText(Node node)

Parameters

node Node

Returns

string

GetHeight(Node, FlowCanvasSettings)

Gets the default height of the node in canvas units (before scaling). Return null to use the default height from settings.

public virtual double? GetHeight(Node node, FlowCanvasSettings settings)

Parameters

node Node
settings FlowCanvasSettings

Returns

double?

GetMinHeight(Node, FlowCanvasSettings)

Gets the minimum height for resizing. Return null for no minimum.

public virtual double? GetMinHeight(Node node, FlowCanvasSettings settings)

Parameters

node Node
settings FlowCanvasSettings

Returns

double?

GetMinWidth(Node, FlowCanvasSettings)

Gets the minimum width for resizing. Return null for no minimum.

public virtual double? GetMinWidth(Node node, FlowCanvasSettings settings)

Parameters

node Node
settings FlowCanvasSettings

Returns

double?

GetWidth(Node, FlowCanvasSettings)

Gets the default width of the node in canvas units (before scaling). Return null to use the default width from settings.

public virtual double? GetWidth(Node node, FlowCanvasSettings settings)

Parameters

node Node
settings FlowCanvasSettings

Returns

double?

IsEditing(Control)

Gets whether the node is currently in edit mode.

public virtual bool IsEditing(Control visual)

Parameters

visual Control

Returns

bool

UpdateSelection(Control, Node, NodeRenderContext)

Updates the visual state when selection changes.

public virtual void UpdateSelection(Control visual, Node node, NodeRenderContext context)

Parameters

visual Control

The node's visual control.

node Node

The node data.

context NodeRenderContext

The rendering context.

UpdateSize(Control, Node, NodeRenderContext, double, double)

Updates the size of an existing node visual.

public virtual void UpdateSize(Control visual, Node node, NodeRenderContext context, double width, double height)

Parameters

visual Control

The node's visual control.

node Node

The node data.

context NodeRenderContext

The rendering context.

width double

The new width in canvas units.

height double

The new height in canvas units.

Remarks

IMPORTANT: Implementations MUST update ALL child elements within the visual, not just the root container. Failing to update child elements will cause the visual to appear unchanged during resize operations until a full re-render occurs.

For composite visuals (e.g., a Grid containing Rectangles, Borders, or Canvases), iterate through children and update their Width/Height properties accordingly.

public void UpdateSize(Control visual, Node node, NodeRenderContext context, double width, double height)
{
    var scaledWidth = width * context.Scale;
    var scaledHeight = height * context.Scale;

    if (visual is Grid grid)
    {
        grid.Width = scaledWidth;
        grid.Height = scaledHeight;

        // CRITICAL: Also update all child elements
        foreach (var child in grid.Children)
        {
            if (child is Rectangle rect)
            {
                rect.Width = scaledWidth;
                rect.Height = scaledHeight;
            }
        }
    }
}