Undo Redo Commands in WPF Diagram (SfDiagram)

26 Jun 20241 minute to read

The Undo command reverses the last editing action performed. For example, some of the basic operations performed on diagram objects such as translation, rotation, resizing, grouping, ungrouping, changing z-order, addition, deletion, and so on, can be reversed. The Redo command restores the last editing action if no other actions have occurred since the last undo.

Undo and Redo actions are disabled by default, to enable this you can use the Constraints property of the SfDiagram. Please refer to the GraphConstraints.

<Syncfusion:SfDiagram x:Name="diagramcontrol" Constraints="Default,Undoable"/>

<Button Height="50" Content="Undo" Name="Undo" Command="Syncfusion:DiagramCommands.Undo"></Button>

<Button Height="50" Content="Redo" Name="Redo" Command="Syncfusion:DiagramCommands.Redo"></Button>
// To enable the Undo and Redo action
diagramcontrol.Constraints |= GraphConstraints.Undoable;

IGraphInfo graphinfo = diagramcontrol.Info as IGraphInfo;

// To perform the Undo action in Diagram
graphinfo.Commands.Undo.Execute(null);

// To Perform the Redo action in Diagram
graphinfo.Commands.Redo.Execute(null);

Undo Redo gif

View sample in GitHub