Skip to content

Custom Node

A 'text updater' node drawn by a NodeTemplate: its own markup, a text field bound to the node's Data, and handles placed by hand - one target and two named sources. Each output node shows what reaches it along the edges: the text from handle a, its length from handle b.

hello
5 characters
bit Blow

Try it

  • Type in the field: the output under handle a mirrors the text, and the one under handle b counts its characters. Backspace edits the text rather than deleting the node.
  • Drag the node by anything but the field: pressing or selecting in the field never moves it.
  • Click an edge to select it, then drag the dot at its lower end onto the other output - or press Delete: each output shows what now reaches it, or (not connected).
  • Drag from handle a or b to an output to wire it up again.

How it works

  • NodeTemplate renders the content of every node. It switches on node.Type and hands every other type back to the built-in renderer with <BlowDefaultNode Node="node" />. With a template, the add-ons go in an explicit <ChildContent>.
  • Data carries the node's payload, a TextData here: the field writes to it, and the page works the outputs' Label out again.
  • Each BlowHandle is placed by hand with its Type and Position. The two source handles need an Id each, which edges name through SourceHandle; Style="left: 25%" moves a handle along its side.
  • The field carries the nodrag class (the canvas's NoDragClass), so a press on it neither selects nor drags the node; graph keys such as Backspace are ignored while focus is in a text field.
  • EdgesChanged is raised after the canvas changes the edge list - a connect, a reconnect or a delete - and the page reads the outputs off the edges again.
  • The template renders inside the node element, so it keeps the node's padding, border and background; Width = 170 gives the field room.
An unhandled error has occurred. Reload 🗙