Skip to content

Validation

One IsValidConnection predicate on the canvas decides which connections are allowed, and it is asked while you drag: every handle turns green or red, and a drop on a red one connects nothing. Use it for the rules of your own application - which node may feed which.

Drag from A's handle.
A (source)
B
accepts A
C
refuses A
bit Blow

Try it

  • Drag from A's handle on the right: while you drag, the handle of every node that would accept the connection turns green and the others red.
  • Release on the green handle to connect, or on the red one to see that nothing happens; the line beside the toolbar says how the attempt ended.
  • Drag again from A to a node it is already connected to: that handle is red now too, because the canvas refuses duplicate edges before your rule is even asked.
  • Drag the other way, from B's or C's handle back to A: the same rule decides, because the connection it is shown always runs from source to target.
  • Change Accept connections into and drag again: the rule is asked afresh on every move, so the colours follow at once. Remove edges starts over.

How it works

  • IsValidConnection on the canvas is a Func<BlowConnection, bool>. It receives the connection completing would make - Source, Target, SourceHandle, TargetHandle, normalised so Source is the source end - and false refuses it.
  • It runs for every handle on every frame of the drag, so keep it cheap. It is only asked about connections the built-in rules (handle types, duplicates, self-connections) already allow.
  • While dragging, the canvas gives each handle bit-blow-handle-valid (green, with a ring) or bit-blow-handle-invalid (red, dimmed); the handle the drag came from gets bit-blow-handle-connectingfrom.
  • The pale green and red at rest are this page's own hint, set through the handle's --bit-blow-handle-bg custom property in its Class, so the live colours still win while a connection is dragged.
  • OnConnect reports the connection that was made. OnConnectEnd reports every attempt: when IsValid is false, Rejection says why a handle refused - RejectedByRule for this predicate - and IsDropped tells a drop on empty space from a click or Escape.
An unhandled error has occurred. Reload 🗙