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
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
rootControl
Returns
GetMetadata(Control)
Gets the resize metadata from a visual, if present.
public static ResizableVisual.ResizeMetadata? GetMetadata(Control visual)
Parameters
visualControl
Returns
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
tagobjectThe 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
visualControl
Returns
TagContainsNode(object?)
Checks if a control's Tag contains a Node (either directly or in dictionary).
public static bool TagContainsNode(object? tag)
Parameters
tagobject
Returns
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
visualControlThe visual returned from CreateNodeVisual.
scaledWidthdoubleWidth in screen units (already multiplied by scale).
scaledHeightdoubleHeight 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
childControlThe child control.
updaterAction<Control, double, double>Action that receives (control, scaledWidth, scaledHeight).
Returns
WithFullSizeChild(Control)
Registers a child that should be resized to match the full parent size.
public ResizableVisual WithFullSizeChild(Control child)
Parameters
childControl
Returns
WithFullSizeChildren(params Control[])
Registers multiple children that should be resized to match the full parent size.
public ResizableVisual WithFullSizeChildren(params Control[] children)
Parameters
childrenControl[]
Returns
WithInsetChild(Control, Thickness)
Registers a child with inset margins (content area sizing).
public ResizableVisual WithInsetChild(Control child, Thickness insets)
Parameters
childControlThe child control.
insetsThicknessThickness representing padding/margins to subtract from full size.
Returns
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
nodeNodeThe node to associate with this visual.