This is more of a conceptual question. If it helps, lets say it falls into the MVVM pattern. I've never seen this addressed in any of my research into WPF Binding.
If you have a window where you have elements connected to view-model through binding and the user updates the record, but before saving decides to cancel the update, what would you consider the best method of reversing the changes would be?
I can think of a couple of possibilities:
- Instead of allowing the user to update the main display, have a second window pop up for editing that is bound to a copy of the VM and upon "Save", writes that data into the original VM and then updates back to the model. Increases memory usage and complexity of the Save function.
- Make a "pristine" copy of the original VM object and, upon "Cancel", write that VM back over the original (at which time the copy can be deleted). Increases memory usage and complexity of the Cancel function.
- Create a copy of each of the elements within the VM that might change upon creation and upon "Cancel", write those values back over the changed ones. Increases the size and complexity of the VM.
- Upon executing "Cancel", the VM hits the data source and reloads the record. Causes network traffic and DB access traffic and possibly lag time for display updating back to original state. Also might cause problems if the VM was updated from another process and these "external" updates should not be deleted.
Can anyone think of a better solution to this problem, or know of some obscure functionality within WPF that handles this "automatically"?