views:

95

answers:

2

I am probably mixing up some responsibilities (and maybe even terminology) here, but I can't quite wrap my head around this.

Is there any relationship between the Command Pattern and the Commands found in MVVM Light (and therefore aswell in WPF)? I would really love to implement some kind of undo / redo mechanism but can't quite figure out if there is an "MVVM Light way" of doing it.

And if this is not in relation to MVVM Light, how could I approach commanding with Undo / Redo in "raw" by not working against MVVM Light WPF?

+1  A: 

Hi, I don't know of any inherent undo/redo functionality in MVVM or WPF I'm afraid.

MVVM Light is a very good lightweight toolkit for rapidly implementing MVVM only. Any additional patterns you're going to have to implement yourself.

Doobi
+3  A: 

The commanding in MVVM Light and WPF in general is a way to encapsulate arbitrary sets of functionality within a single object and interface, and to wire up any number of UI elements to execute that action.

These commands can be incorporated into a command pattern implementation of undo/redo functionality, but you need more.

You can roll your own command stack, which is the route I've taken in my current WPF project (using Prism).

Basically, it is a shift of mindset where every change that a user can make through the UI

  1. is wrapped in a command
  2. has a corresponding undo command
  3. gets pushed to a stack

There are also open-source projects available to help with this, including http://undo.codeplex.com/, which is a side project of Kirill Osenkov, a member of the Visual Studio team.

Jay