I'm working on a Silverlight LoB app which the designers want to have a tabbed-interface, similar to the interface of Visual Studio (we'll probably use the Telerik Rad controls for docking tabs). Having done a prototype, the interface is working well so far, but I'm having problems thinking of how to implement undo/redo functionality in an MVVM project.
The undo/redo functionality has to:
- On undo/redo, restore the UI state, i.e. return focus, selection etc. to the control(s) (such as a textbox) that the change originated from.
- Have a per-view undo/redo stack
Typically, I'd use the command pattern, but I'm not sure how to apply that with MVVM.
I've used commanding & binding to get the idealised loose-coupling of the views & view-models, but it makes undo/redo a lot trickier, since the view-model doesn't have any concept of the view and the state of the view when a command is received or a bound property is changed. It seems that I need some kind of service tracking which view is active whenever the user performs some undoable action and gets the state for later restoration.
Is there any consensus on what is the best-practise for implmenting undo/redo in MVVM? I've looked with interest at how Daniel Vaughan does it in his Calcium project; Blend was apparently written using the MVVM pattern and it behaves just as I want my app to, it'd be great if MS explained how they did it!