Creating an undo/redo system
Up until now we have been executing commands by using the RelayCommand
helper class. This allows us to separate the command implementation (in the ViewModel) from the view without creating a separate class for each command. Many applications need to not only execute commands, but also to undo already executed commands; the canonical case may be a text editor, but it can be anything. Let's see one way to build an undo/redo system that integrates with the commands infrastructure we've seen so far.
Getting ready
We'll use two projects we've already created. The first is CH07.CookbookMVVM
, our MVVM framework (which we'll expand), and there is also CH07.BlogReader
to demonstrate adding undo/redo capabilities.
How to do it...
We'll add undo/redo capabilities to the blog reader application, both at the MVVM framework level and application level:
Add a new interface to the
CH07.CookbookMVVM
project and name itIUndoCommand
. Define it as follows:public interface IUndoCommand...