Controlled vs Uncontrolled
The canvas always edits the lists it is given in place; what differs is whether the page is told. Controlled, the page handles NodesChanged and EdgesChanged and keeps its own view of the graph current after every edit. Uncontrolled, it handles nothing and learns what changed only when it asks the canvas.
Press Tab to move between the nodes and edges of the diagram.
Press Enter or Space to select it, Shift with Enter to add it to the selection, the arrow keys to move the selected nodes, Delete to remove them and Escape to clear the selection. Press C to start a connection from it.
Press Enter or Space to select it, Delete to remove it and Escape to clear the selection. Press C to move its end to another node.
bit BlowTry it
- With Controlled ticked, drag Node 1: the readout updates when you let go, not while the node moves.
- Drag from a handle to another node to connect them, or select something and press Delete: the counts follow each edit.
- Untick Controlled and do the same: the canvas still works, but the readout stays where it was - the page was not told.
- Press Ask the canvas to read the graph as it is now. Ticking Controlled again also catches up, since the page reads the graph on taking control.
How it works
- In both modes
NodesandEdgesare the page's own lists, and the canvas adds, moves and removes items in them directly: nothing is copied, so there is no second graph to fall out of step. - Controlled hands the canvas
NodesChangedandEdgesChangedhandlers. They are raised once an edit is complete - a drag released, a connection made, something deleted, pasted or nudged with the keys - with the list itself, and the page re-renders after each. - Uncontrolled passes
defaultfor both callbacks, so nothing is raised and the page's copy of the counts goes stale. Ask the canvas reads the graph through the component reference withToObject(deep: false), aBlowSnapshotof the live nodes and edges, without copying them. Nodes/NodesChangedandEdges/EdgesChangedare bindable pairs, so@bind-Nodes="_nodes"compiles too; since the list instance never changes, the binding is mostly a signal to persist.- For the kind of edit as well as the fact of one - who made it and what it touched - handle
OnGraphChangedinstead;/examples/groupinglogs it.