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... ...

Get Windows Presentation Foundation 4.5 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.