Table of Contents

Class CanvasElement

Namespace
FlowGraph.Core.Elements
Assembly
FlowGraph.Core.dll

Base class for all elements that can be placed on the canvas. Provides common properties for positioning, sizing, selection, and visibility.

public abstract class CanvasElement : ICanvasElement, INotifyPropertyChanged
Inheritance
CanvasElement
Implements
Derived
Inherited Members

Examples

// Creating a custom element
public class MyCustomElement : CanvasElement
{
    public override string Type => "custom";

    public MyCustomElement() : base(Guid.NewGuid().ToString()) { }
}

Remarks

This is the foundation of the canvas-first architecture. All visual elements (nodes, edges, shapes, annotations) extend this class.

Constructors

CanvasElement(string)

Creates a new canvas element with the specified ID.

protected CanvasElement(string id)

Parameters

id string

The unique identifier for this element.

Fields

ZIndexBackground

Default Z-index for background elements.

public const int ZIndexBackground = 0

Field Value

int

ZIndexEdges

Default Z-index for edge elements.

public const int ZIndexEdges = 200

Field Value

int

ZIndexGroups

Default Z-index for group nodes. Groups render below regular nodes so their children appear on top.

public const int ZIndexGroups = 150

Field Value

int

ZIndexNodes

Default Z-index for node elements.

public const int ZIndexNodes = 300

Field Value

int

ZIndexShapes

Default Z-index for shape elements.

public const int ZIndexShapes = 100

Field Value

int

Properties

Height

Gets or sets the height of this element, if applicable.

public double? Height { get; set; }

Property Value

double?

Remarks

Some elements (like edges) may not have a meaningful height. Returns null if the element has no explicit height.

Id

Gets the unique identifier for this element.

public string Id { get; }

Property Value

string

Remarks

IDs are immutable after creation and used for lookups, serialization, and change tracking.

IsSelectable

Gets or sets whether this element can be selected by user interaction.

public bool IsSelectable { get; set; }

Property Value

bool

Remarks

When false, clicking on the element will not select it.

IsSelected

Gets or sets whether this element is currently selected.

public bool IsSelected { get; set; }

Property Value

bool

IsVisible

Gets or sets whether this element is visible.

public bool IsVisible { get; set; }

Property Value

bool

Remarks

Invisible elements are not rendered but remain in the element collection.

Position

Gets or sets the position of this element in canvas coordinates.

public Point Position { get; set; }

Property Value

Point

Remarks

The position typically represents the top-left corner of the element's bounding box, but this may vary by element type.

Type

Gets the type identifier for this element.

public abstract string Type { get; }

Property Value

string

Remarks

Used by renderer registries to select the appropriate renderer. For nodes, this typically comes from the node definition's Type property. For shapes, this identifies the shape type (line, rectangle, text, etc.).

Width

Gets or sets the width of this element, if applicable.

public double? Width { get; set; }

Property Value

double?

Remarks

Some elements (like edges) may not have a meaningful width. Returns null if the element has no explicit width.

ZIndex

Gets the Z-index for rendering order.

public int ZIndex { get; set; }

Property Value

int

Remarks

Higher values render on top. Default values by type:

  • Backgrounds: 0
  • Shapes: 100
  • Edges: 200
  • Nodes: 300

Methods

GetBounds()

Gets the bounding rectangle of this element in canvas coordinates.

public virtual Rect GetBounds()

Returns

Rect

The bounds as a Rect.

OnBoundsChanged()

Called when any bounds-related property changes. Override to respond to bounds changes.

protected virtual void OnBoundsChanged()

OnPropertyChanged(string)

Raises the PropertyChanged event.

protected virtual void OnPropertyChanged(string propertyName)

Parameters

propertyName string

Name of the property that changed.

Events

PropertyChanged

Occurs when a property value changes.

public event PropertyChangedEventHandler? PropertyChanged

Event Type

PropertyChangedEventHandler