Undo and redo are provided by the graph out-of-the-box, but have to be enabled before they can be used. The easiest way to do this is to enable them on both the default graph and the input mode.
To enable undo on the default graph, retrieve it and and set its UndoEngineEnabled property to true.
Example 3.23. Enabling Undo
IGraph graph = GetMyGraph(); // Retrieve the default graph and enable the undo feature graph.Get<DefaultGraph>().UndoEngineEnabled = true;
By default, clipboard support is enabled on the graph. However, to use it with the default keyboard shortcuts, you must also enable it on the input mode. Once you've enabled it, the application commands for cut, copy, and paste will work and can be triggered by the standard keyboard commands Ctrl-X, Ctrl-C and Ctrl-V.
To enable clipboard support, set the input mode's ClipboardOperationsAllowed property to true.
Example 3.25. Enabling Clipboard
GraphEditorInputMode inputMode = GetMyGraphEditorInputMode(); // Enable clipboard operations on the input mode inputMode.ClipboardOperationsAllowed = true;
It is possible to customize undo and clipboard operations. For example, if you copy a collection of nodes and edges, paste might only duplicate the nodes, or it could apply a new style to the elements.
The undo engine supports the basic graph operations such as adding, moving, and removing elements; changing styles, etc. However, your application may have additional custom operations, for example operations on business data stored in an element's tag. To be able to undo and redo a custom operation, you must make a custom undo unit so that the operation can be added to the undo queue.
Adding new operation types is an advanced topic that is covered in the yFiles for Silverlight tutorial, see especially step 07.
Copyright ©2004-2015, yWorks GmbH. All rights reserved.