Table of Contents

Class ViewportOverlayPositioner

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

Provides unified positioning for overlay elements that need to appear at specific viewport coordinates, regardless of the parent container type.

Problem this solves: FlowGraph has two rendering modes with different container types:

  • Retained Mode: Uses MainCanvas (Canvas) with MatrixTransform - Canvas.SetLeft/SetTop work
  • Direct Rendering: Uses RootPanel (Panel) - Canvas.SetLeft/SetTop are IGNORED

Key insight: Canvas attached properties (Canvas.Left, Canvas.Top) only work when the parent element is a Canvas. When attached to a Panel child, they have no effect.

public class ViewportOverlayPositioner
Inheritance
ViewportOverlayPositioner
Inherited Members

Examples

// Instead of this error-prone code:
if (isDirectMode)
{
    // BUG: Won't work - RootPanel is Panel, not Canvas!
    Canvas.SetLeft(element, x);
    Canvas.SetTop(element, y);
}

// Use the positioner:
var positioner = new ViewportOverlayPositioner(isDirectMode);
positioner.SetPosition(element, viewportX, viewportY);

Constructors

ViewportOverlayPositioner(bool)

Creates a new viewport overlay positioner.

public ViewportOverlayPositioner(bool isDirectRenderingMode)

Parameters

isDirectRenderingMode bool

True when using Direct Rendering (RootPanel/Panel parent). False when using Retained Mode (MainCanvas/Canvas parent).

Methods

Create(DirectCanvasRenderer?)

Creates a positioner based on whether a direct renderer is active.

public static ViewportOverlayPositioner Create(DirectCanvasRenderer? directRenderer)

Parameters

directRenderer DirectCanvasRenderer

The direct renderer, or null if in retained mode.

Returns

ViewportOverlayPositioner

A positioner configured for the current rendering mode.

PrepareForPositioning(Control)

Sets up an element for proper positioning in the target container. Call this when creating elements that will be positioned later.

public void PrepareForPositioning(Control element)

Parameters

element Control

The element to configure.

Remarks

This sets HorizontalAlignment and VerticalAlignment to Left/Top for Panel parents. For Canvas parents, these properties are ignored but don't cause harm.

SetPosition(Control, Point)

Positions an element at the specified Avalonia point (viewport coordinates).

public void SetPosition(Control element, Point position)

Parameters

element Control

The element to position.

position Point

Position in viewport space.

SetPosition(Control, ViewportPoint)

Positions an element at the specified viewport point.

public void SetPosition(Control element, ViewportPoint position)

Parameters

element Control

The element to position.

position ViewportPoint

Position in viewport space.

SetPosition(Control, double, double)

Positions an element at the specified viewport coordinates. Automatically uses the correct positioning method based on the rendering mode.

public void SetPosition(Control element, double x, double y)

Parameters

element Control

The element to position.

x double

X coordinate in viewport space.

y double

Y coordinate in viewport space.