Skip to content

Custom Connection Line

The line drawn while you connect can be restyled with ConnectionLineStyle and ConnectionLineClass, or drawn entirely by you with a ConnectionLineTemplate - here a dashed gradient with a dot at the pointer that turns green over a handle that would accept the connection.

Drag from here
Node B
Node C
bit Blow

Try it

  • Drag from the handle under "Drag from here" (or from any node's bottom handle) and move around: the line follows the pointer.
  • Bring the pointer near the top handle of Node B or Node C: with the custom template, the gradient's far end and the dot at the pointer turn green, because releasing there would connect.
  • Switch Line to Default, restyled for the built-in line in a thicker amber stroke with marching dashes, or to Default for the line as it comes.
  • Change Shape to draw the line as a bezier, smooth step, step or straight line - whichever line is shown.

How it works

  • ConnectionLineTemplate is a RenderFragment<BlowConnectionLineContext> drawn inside the canvas's SVG, in flow coordinates, instead of the built-in line. Here it is a page field handed over only while Custom template is picked; null brings the built-in line back.
  • The context carries FromNode, FromHandle, FromHandleType, the start point From and its side FromPosition, the pointer To and the side ToPosition the line arrives from, and IsValid - true when releasing now would connect, including within ConnectionRadius of a handle that would accept it.
  • BlowEdgePath.Compute(type, ...) turns those points and sides into an SVG path, the same geometry edges use; the template passes it the Shape. The gradient uses gradientUnits="userSpaceOnUse" so it always runs from the handle to the pointer.
  • For the built-in line, ConnectionLineType (default Bezier) picks the shape, ConnectionLineStyle adds an inline style - stroke:#f59e0b;stroke-width:3 here - and ConnectionLineClass a class of your stylesheet, this page's ccl-marching. All three are ignored while a template draws the line.
An unhandled error has occurred. Reload 🗙