title: How to implement undo/redo in a MVVM application?
body: <p>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. </p>
  
  <p>The undo/redo functionality has to: </p>
  
  <ol>
  <li>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.</li>
  <li>Have a per-view undo/redo stack</li>
  </ol>
  
  <p>Typically, I'd use the command pattern, but I'm not sure how to apply that with MVVM. </p>
  
  <p>I've used commanding &amp; binding to get the idealised loose-coupling of the views &amp; 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. </p>
  
  <p>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!</p>