Search
Overview

Interactive actions, carried out by users, and programmatic commands that change the structure of a diagram are recorded in a history queue. While action records are still in that queue, the actions can be undone or redone. The queue has a fixed length - if it gets full, recording a new action makes the oldest one drop from the queue.

Undo is disabled by default. To enable it, set the UndoEnabled property to true. To undo or redo an action, call the Undo or Redo methods of UndoManager. WpfDiagram does not provide keyboard shortcuts for undo/redo. Your application must have its own menu items and/or keyboard accelerators to provide the necessary user interface, and invoke the respective methods in response to UI events.

WpfDiagram automatically saves the following types of actions for later undo/redo:

  • adding an item to the diagram
  • removing an item from the diagram
  • moving or resizing items
  • creating a group
  • destroying a group
  • expanding or collapsing trees
  • scrolling table rows
  • adding or removing tables' rows

Changes to property values are not saved automatically in the history. If your application must be able to undo/redo property changes, use the ChangeItemCmd command. ChangeItemCmd allows recording several property changes as an atomic undoable action.

In some cases you may need to create your own types of actions or commands. For example, suppose you need to implement undo/redo for changes made to the Tag property of items or changes to controls embedded in ControlNode items. However, WpfDiagram is not able to detect such changes, so it cannot undo them. To enable undo/redo you would have to create a subclass of Command and implement its Execute, Undo and Redo methods.