Class CanvasElementManager
Coordinates rendering of all graph elements (nodes, ports, edges, handles). Acts as a facade over specialized visual managers for clean separation of concerns.
public class CanvasElementManager
- Inheritance
-
CanvasElementManager
- Inherited Members
Constructors
CanvasElementManager()
Creates a new graph renderer with default settings.
public CanvasElementManager()
CanvasElementManager(FlowCanvasSettings?)
Creates a new graph renderer with the specified settings.
public CanvasElementManager(FlowCanvasSettings? settings)
Parameters
settingsFlowCanvasSettingsCanvas settings. If null, default settings are used.
CanvasElementManager(FlowCanvasSettings?, NodeRendererRegistry?)
Creates a new graph renderer with the specified settings and node renderer registry.
public CanvasElementManager(FlowCanvasSettings? settings, NodeRendererRegistry? nodeRendererRegistry)
Parameters
settingsFlowCanvasSettingsCanvas settings. If null, default settings are used.
nodeRendererRegistryNodeRendererRegistryRegistry for custom node renderers. If null, a default registry is created.
Properties
BackgroundRenderers
Gets the background renderer registry for custom background rendering.
public BackgroundRendererRegistry BackgroundRenderers { get; }
Property Value
EdgeRenderers
Gets the edge renderer registry for registering custom edge types.
public EdgeRendererRegistry EdgeRenderers { get; }
Property Value
Edges
Gets the edge visual manager.
public EdgeVisualManager Edges { get; }
Property Value
NodeRenderers
Gets the node renderer registry for registering custom node types.
public NodeRendererRegistry NodeRenderers { get; }
Property Value
Nodes
Gets the node visual manager.
public NodeVisualManager Nodes { get; }
Property Value
PortRenderers
Gets the port renderer registry for registering custom port types.
public PortRendererRegistry PortRenderers { get; }
Property Value
RenderContext
Gets the render context for coordinate transformations.
public RenderContext RenderContext { get; }
Property Value
ResizeHandles
Gets the resize handle manager.
public ResizeHandleManager ResizeHandles { get; }
Property Value
Methods
BeginEditLabel(Node, ThemeResources, Action<string>, Action)
Begins inline editing for a node's label.
public bool BeginEditLabel(Node node, ThemeResources theme, Action<string> onCommit, Action onCancel)
Parameters
nodeNodeThe node to edit.
themeThemeResourcesTheme resources for styling.
onCommitAction<string>Callback when editing is committed with the new label value.
onCancelActionCallback when editing is cancelled.
Returns
- bool
True if edit mode was started successfully.
Clear()
Clears all rendered visuals from tracking.
public void Clear()
EndEditLabel(Node, ThemeResources)
Ends inline editing for a node's label.
public void EndEditLabel(Node node, ThemeResources theme)
Parameters
nodeNodeThe node being edited.
themeThemeResourcesTheme resources for styling.
GetEdgeEndpointHandles(string)
Gets the endpoint handles for an edge.
public (Ellipse? source, Ellipse? target) GetEdgeEndpointHandles(string edgeId)
Parameters
edgeIdstring
Returns
GetEdgeGlowPath(string)
Gets the glow path for an edge (background glow effect).
public Path? GetEdgeGlowPath(string edgeId)
Parameters
edgeIdstring
Returns
- Path
GetEdgeLabel(string)
Gets the edge label for an edge.
public TextBlock? GetEdgeLabel(string edgeId)
Parameters
edgeIdstring
Returns
- TextBlock
GetEdgeMarkers(string)
Gets the markers (arrows) for an edge.
public IReadOnlyList<Path>? GetEdgeMarkers(string edgeId)
Parameters
edgeIdstring
Returns
- IReadOnlyList<Path>
GetEdgeVisiblePath(string)
Gets the visible path for an edge (the actual rendered stroke).
public Path? GetEdgeVisiblePath(string edgeId)
Parameters
edgeIdstring
Returns
- Path
GetEdgeVisual(string)
Gets the visual element for an edge (hit area path).
public Path? GetEdgeVisual(string edgeId)
Parameters
edgeIdstring
Returns
- Path
GetNodeDimensions(Node)
Gets the dimensions for a node, considering custom renderer sizes and node-specific overrides.
public (double width, double height) GetNodeDimensions(Node node)
Parameters
nodeNode
Returns
GetNodeVisual(string)
Gets the visual element for a node.
public Control? GetNodeVisual(string nodeId)
Parameters
nodeIdstring
Returns
- Control
GetPortCanvasPosition(Node, Port, bool)
Gets the port position in canvas coordinates. Use this for drawing visual elements on MainCanvas (which uses MatrixTransform).
public Point GetPortCanvasPosition(Node node, Port port, bool isOutput)
Parameters
Returns
- Point
GetPortScreenPosition(Node, Port, bool)
Gets the port position in screen coordinates.
[Obsolete("Use GetPortViewportPosition or GetPortCanvasPosition instead.")]
public Point GetPortScreenPosition(Node node, Port port, bool isOutput)
Parameters
Returns
- Point
GetPortViewportPosition(Node, Port, bool)
Gets the port position in viewport coordinates.
public Point GetPortViewportPosition(Node node, Port port, bool isOutput)
Parameters
Returns
- Point
Remarks
WARNING: For distance calculations with pointer events, prefer using GetPortCanvasPosition(Node, Port, bool)
since pointer events give canvas coords via e.GetPosition(MainCanvas).
GetPortVisual(string, string)
Gets the visual element for a port.
public Control? GetPortVisual(string nodeId, string portId)
Parameters
Returns
- Control
GetPortY(double, int, int)
Calculates the Y position for a port (legacy, returns canvas coordinates).
public double GetPortY(double nodeY, int portIndex, int totalPorts)
Parameters
Returns
GetPortYCanvas(double, int, int, double?)
Calculates the Y position for a port in canvas coordinates.
public double GetPortYCanvas(double nodeY, int portIndex, int totalPorts, double? nodeHeight = null)
Parameters
Returns
GetShapeVisual(string)
Gets the visual element for a shape.
public Control? GetShapeVisual(string shapeId)
Parameters
shapeIdstring
Returns
- Control
HasEdgeVisual(string)
Checks if an edge visual exists.
public bool HasEdgeVisual(string edgeId)
Parameters
edgeIdstring
Returns
HasNodeVisual(string)
Checks if a node visual exists.
public bool HasNodeVisual(string nodeId)
Parameters
nodeIdstring
Returns
IsEditingLabel(Node)
Gets whether a node is currently in edit mode.
public bool IsEditingLabel(Node node)
Parameters
nodeNodeThe node to check.
Returns
- bool
True if the node is being edited.
IsNodeVisible(Graph, Node)
Checks if a node is visible (not hidden by a collapsed ancestor group).
public bool IsNodeVisible(Graph graph, Node node)
Parameters
Returns
RemoveAllResizeHandles(Canvas)
Removes all resize handles from the canvas.
public void RemoveAllResizeHandles(Canvas canvas)
Parameters
canvasCanvas
RemoveEdgeVisual(Canvas, Edge)
Removes a single edge visual from the canvas.
public bool RemoveEdgeVisual(Canvas canvas, Edge edge)
Parameters
canvasCanvasThe canvas containing the visual.
edgeEdgeThe edge to remove.
Returns
- bool
True if the visual was found and removed.
RemoveNodeVisual(Canvas, Node)
Removes a single node visual and its ports from the canvas.
public bool RemoveNodeVisual(Canvas canvas, Node node)
Parameters
canvasCanvasThe canvas containing the visual.
nodeNodeThe node to remove.
Returns
- bool
True if the visual was found and removed.
RemoveResizeHandles(Canvas, string)
Removes resize handles for a node.
public void RemoveResizeHandles(Canvas canvas, string nodeId)
Parameters
canvasCanvasnodeIdstring
RenderEdge(Canvas, Edge, Graph, ThemeResources)
Renders a single edge with its markers and optional label.
public Path? RenderEdge(Canvas canvas, Edge edge, Graph graph, ThemeResources theme)
Parameters
canvasCanvasedgeEdgegraphGraphthemeThemeResources
Returns
- Path
RenderEdges(Canvas, Graph, ThemeResources, Path?)
Renders all edges in the graph. Edges with hidden endpoints (due to collapsed groups) are not rendered.
public void RenderEdges(Canvas canvas, Graph graph, ThemeResources theme, Path? excludePath = null)
Parameters
canvasCanvasgraphGraphthemeThemeResourcesexcludePathPath
RenderNode(Canvas, Node, ThemeResources, Action<Control, Node>?)
Renders a single node using the appropriate renderer for its type.
public Control RenderNode(Canvas canvas, Node node, ThemeResources theme, Action<Control, Node>? onNodeCreated = null)
Parameters
canvasCanvasnodeNodethemeThemeResourcesonNodeCreatedAction<Control, Node>
Returns
- Control
RenderNodes(Canvas, Graph, ThemeResources, Action<Control, Node>)
Renders all nodes in the graph. Groups are rendered first (behind), then regular nodes. Nodes hidden by collapsed groups are not rendered.
public void RenderNodes(Canvas canvas, Graph graph, ThemeResources theme, Action<Control, Node> onNodeCreated)
Parameters
canvasCanvasgraphGraphthemeThemeResourcesonNodeCreatedAction<Control, Node>
RenderPort(Canvas, Node, Port, int, int, bool, ThemeResources, Action<Control, Node, Port, bool>?)
Renders a single port.
public Control RenderPort(Canvas canvas, Node node, Port port, int index, int totalPorts, bool isOutput, ThemeResources theme, Action<Control, Node, Port, bool>? onPortCreated = null)
Parameters
canvasCanvasnodeNodeportPortindexinttotalPortsintisOutputboolthemeThemeResourcesonPortCreatedAction<Control, Node, Port, bool>
Returns
- Control
RenderResizeHandles(Canvas, Node, ThemeResources, Action<Rectangle, Node, ResizeHandlePosition>?)
Renders resize handles for a selected node.
public void RenderResizeHandles(Canvas canvas, Node node, ThemeResources theme, Action<Rectangle, Node, ResizeHandlePosition>? onHandleCreated = null)
Parameters
canvasCanvasnodeNodethemeThemeResourcesonHandleCreatedAction<Rectangle, Node, ResizeHandlePosition>
SetShapeVisualManager(ShapeVisualManager?)
Sets the shape visual manager for delegating shape operations.
public void SetShapeVisualManager(ShapeVisualManager? manager)
Parameters
managerShapeVisualManager
SetViewport(ViewportState?)
Sets the viewport state to use for coordinate transformations.
public void SetViewport(ViewportState? viewport)
Parameters
viewportViewportStateThe viewport state.
SupportsEditing(string?)
Checks if a node's renderer supports inline editing.
public bool SupportsEditing(string? nodeType)
Parameters
nodeTypestringThe node type to check.
Returns
- bool
True if the renderer supports editing.
TriggerPortDataPulse(Node, Port, ThemeResources)
Triggers a data pulse animation on a specific port.
public void TriggerPortDataPulse(Node node, Port port, ThemeResources theme)
Parameters
nodeNodeportPortthemeThemeResources
TriggerPortError(Node, Port, string?)
Triggers an error animation on a specific port.
public void TriggerPortError(Node node, Port port, string? message = null)
Parameters
TriggerPortSuccess(Node, Port)
Triggers a success animation on a specific port.
public void TriggerPortSuccess(Node node, Port port)
Parameters
UpdateAllNodePositions(Graph)
Updates all node positions for viewport changes (pan/zoom). This is an optimized path that avoids recreating the visual tree.
public void UpdateAllNodePositions(Graph graph)
Parameters
graphGraph
UpdateAllPortStates(Graph, ThemeResources)
Updates the visual state of all ports in the graph based on their connection status. This should be called after rendering to ensure animated ports start their animations.
public void UpdateAllPortStates(Graph graph, ThemeResources theme)
Parameters
graphGraphthemeThemeResources
UpdateAllResizeHandles()
Updates size and position of all tracked resize handles. Called on zoom changes to recalculate InverseScale-based sizing.
public void UpdateAllResizeHandles()
UpdateEdgeSelection(Edge, ThemeResources)
Updates the selection visual of an edge.
public void UpdateEdgeSelection(Edge edge, ThemeResources theme)
Parameters
edgeEdgethemeThemeResources
UpdateNodePosition(Node)
Updates the position of a node visual.
public void UpdateNodePosition(Node node)
Parameters
nodeNode
UpdateNodeSelection(Node, ThemeResources)
Updates the selection visual of a node.
public void UpdateNodeSelection(Node node, ThemeResources theme)
Parameters
nodeNodethemeThemeResources
UpdateNodeSize(Node, ThemeResources)
Updates the size of a node visual.
public void UpdateNodeSize(Node node, ThemeResources theme)
Parameters
nodeNodethemeThemeResources
UpdateNodeStyle(Node, ThemeResources)
Updates the custom style of a node based on its Data property.
public void UpdateNodeStyle(Node node, ThemeResources theme)
Parameters
nodeNodethemeThemeResources
UpdatePortPositions(Node)
Updates port positions for a node.
public void UpdatePortPositions(Node node)
Parameters
nodeNode
UpdatePortState(Node, Port, PortVisualState, ThemeResources)
Updates the visual state of a port using its renderer.
public void UpdatePortState(Node node, Port port, PortVisualState state, ThemeResources theme)
Parameters
nodeNodeportPortstatePortVisualStatethemeThemeResources
UpdateResizeHandlePositions(Node)
Updates the position of resize handles for a node.
public void UpdateResizeHandlePositions(Node node)
Parameters
nodeNode
UpdateSettings(FlowCanvasSettings)
Updates the settings used by this renderer and all its sub-components. Call this when FlowCanvasSettings property changes to propagate the new values.
public void UpdateSettings(FlowCanvasSettings settings)
Parameters
settingsFlowCanvasSettingsThe new settings to use.
UpdateShapeSelection(string, bool)
Updates the selection visual for a shape.
public void UpdateShapeSelection(string shapeId, bool isSelected)
Parameters
UpdateShapeVisual(ShapeElement)
Updates a shape visual after its properties have changed.
public void UpdateShapeVisual(ShapeElement shape)
Parameters
shapeShapeElement