Table of Contents

Class ResizableVisual

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

A wrapper that tracks resizable child elements within a node visual. When UpdateSize is called, all registered children are automatically updated.

Use this in CreateNodeVisual to ensure UpdateSize properly propagates to all children.

public class ResizableVisual
Inheritance
ResizableVisual
Inherited Members

Examples

public Control CreateNodeVisual(Node node, NodeRenderContext context)
{
    var grid = new Grid { Width = 200, Height = 100 };
    var background = new Rectangle { Width = 200, Height = 100 };
    var border = new Rectangle { Width = 200, Height = 100 };

    grid.Children.Add(background);
    grid.Children.Add(border);

    // Register children that need resizing - this is the key!
    return ResizableVisual.Create(grid)
        .WithFullSizeChild(background)
        .WithFullSizeChild(border)
        .Build();
}

public void UpdateSize(Control visual, Node node, NodeRenderContext context, double w, double h)
{
    // One line - all registered children are automatically updated!
    ResizableVisual.UpdateSize(visual, w * context.Scale, h * context.Scale);
}

Fields

MetadataKey

Tag key used to store resize metadata on the visual.

public const string MetadataKey = "__ResizableVisual"

Field Value

string

Methods

Build()

Builds and returns the root control with resize metadata attached.

public Control Build()

Returns

Control

Create(Control)

Creates a new ResizableVisual builder for the given root control.

public static ResizableVisual Create(Control root)

Parameters

root Control

Returns

ResizableVisual

GetMetadata(Control)

Gets the resize metadata from a visual, if present.

public static ResizableVisual.ResizeMetadata? GetMetadata(Control visual)

Parameters

visual Control

Returns

ResizableVisual.ResizeMetadata

GetNodeFromTag(object?)

Extracts the Node from a control's Tag, handling both direct assignment and dictionary storage (used when ResizableVisual metadata is present).

public static Node? GetNodeFromTag(object? tag)

Parameters

tag object

The Tag value from a control.

Returns

Node

The Node if found, null otherwise.

HasResizeMetadata(Control)

Checks if a visual has resize metadata attached. Useful for validation/debugging.

public static bool HasResizeMetadata(Control visual)

Parameters

visual Control

Returns

bool

TagContainsNode(object?)

Checks if a control's Tag contains a Node (either directly or in dictionary).

public static bool TagContainsNode(object? tag)

Parameters

tag object

Returns

bool

UpdateSize(Control, double, double)

Updates the size of a visual and all its registered children. Call this from INodeRenderer.UpdateSize.

public static bool UpdateSize(Control visual, double scaledWidth, double scaledHeight)

Parameters

visual Control

The visual returned from CreateNodeVisual.

scaledWidth double

Width in screen units (already multiplied by scale).

scaledHeight double

Height in screen units (already multiplied by scale).

Returns

bool

True if resize metadata was found and applied, false if fallback behavior was used.

WithCustomChild(Control, Action<Control, double, double>)

Registers a child with custom resize logic.

public ResizableVisual WithCustomChild(Control child, Action<Control, double, double> updater)

Parameters

child Control

The child control.

updater Action<Control, double, double>

Action that receives (control, scaledWidth, scaledHeight).

Returns

ResizableVisual

WithFullSizeChild(Control)

Registers a child that should be resized to match the full parent size.

public ResizableVisual WithFullSizeChild(Control child)

Parameters

child Control

Returns

ResizableVisual

WithFullSizeChildren(params Control[])

Registers multiple children that should be resized to match the full parent size.

public ResizableVisual WithFullSizeChildren(params Control[] children)

Parameters

children Control[]

Returns

ResizableVisual

WithInsetChild(Control, Thickness)

Registers a child with inset margins (content area sizing).

public ResizableVisual WithInsetChild(Control child, Thickness insets)

Parameters

child Control

The child control.

insets Thickness

Thickness representing padding/margins to subtract from full size.

Returns

ResizableVisual

WithNode(Node)

Associates a Node with this visual for event handling. The node will be stored in the tag dictionary and can be retrieved via GetNodeFromTag.

public ResizableVisual WithNode(Node node)

Parameters

node Node

The node to associate with this visual.

Returns

ResizableVisual