1

I'm currently developping a tool to visualize some models inside a WPF application.

One of my problems is the "live edition" problem using the MVVM pattern.

In the screen shown under, I have my MainWindow with a panel including the MonoGame rendering using: https://github.com/ShyroFR/MonoGame.Interop

The thing is, when i'm going to turn on/off switches or other controls on my "Edit" window, I want the changes to occur on the MainWindow. If I choose to valide the changes, ok, no problem, changes will be made, but if I cancel the edition, the previous version should be back again. (Basicaly just a have to do a save before...)

enter image description here

Thank you for your help, have a good day and happy new year :)

Eastrall
  • 7,609
  • 1
  • 16
  • 30

2 Answers2

2

You should look into implementing an interface like IEditableObject or IRevertibleChangeTracking. Both help to conceptualize the notion of reverting a change. A good discussion on this answer.

That said, both still require deeper thought as to how to handle the internals of cancelling a change. I think the main camps are 'use an immutable object approach' and 'action tracking'. Both have benefits and trade-offs.

Community
  • 1
  • 1
Andrew Hanlon
  • 7,271
  • 4
  • 33
  • 53
1

Command Processor Pattern: http://wiki.hsr.ch/APF/files/CommandProcessor.pdf is a variation of the command pattern from the "Gang of Four" Design Patterns book.

It is a great approach for creating 'command' objects(that also contain the instructions on how to 'undo/inverse' that particular 'command', that way you can store in a stack (of whatever depth you want) of possible 'undo' operands. (you can meld this with your MVVC pattern)

The command pattern also is designed to do this, but I find the 'Command Processor Pattern' more 'clear' on how to actually implement. ('Command Pattern' seems to kind of leaves that up to you to implement.)

mawalker
  • 2,072
  • 2
  • 22
  • 34