Undo-Redo Frameworks For WPF and Silverlight
Undo and Redo are two commands that are commonly expected by users in a rich interface and, when well implemented, can improve an application's usability significantly. However building the functionality from scratch for each application can be time-consuming and repetitive. At least two libraries exist that can help WPF and Silverlight developers - a recently announced Undo-Redo framework from Infragistics (CTP) and an open source library called Undo.
A common way to implement multiple-Undo-Redo functionality is to use the Command Pattern, keeping a stack of command objects for undo. For redo a second stack can have all the commands that are undone. However this simple technique can start getting complicated when you consider following things -
Collections need to be handled separately from Properties
Multiple commands might have to be bunched together – for eg, if you have a textbox bound to a model property, you don’t want each keystroke to be considered as a separate action, even if the model is wired to be updated on each keystroke
This is where undo frameworks can help. The framework from Infragistics provides several features as outlined in their announcement. This includes custom Undo-Units, support for ObservableCollection and Transaction Support. Similarly, there is also an open source framework called Undo, by Kirill Osenkov which supports nested transactions and action merging. You can learn more about this framework in Kirill’s article and in the project documentation.
Note that these are linear undo-redo frameworks – they don’t support non-linear/branched undos (where the user can selectively undo any of the previous actions without undoing everything till that point). Even linear Undo-Redo scenarios can have user-experience challenges, especially when the user expects something to be undone, but that something hasn’t been recorded yet (for eg, user types in a textbox and on tabbing out a validation kicks in so the bound property is not updated) etc.
Hopefully, we will continue to see more work in this area.
Dimitar Bakardzhiev Mar 29, 2015