Hi,
I've tried to find some documentation on how the merging feature of the Undo/Redo framework really works, but can't find anything that really explains the details. Are there any in-depth resources available ?
Questions I have include:
1. If merging is enabled, will e.g. all property changes within a transaction be merged irrespective of any other property changes that happen in-between ?
2 How do merge work with collection changes ?
Regards,Leif
Merging is basically a case where the UndoManager takes the incoming UndoUnit being added and passes that to the Merge method of the last UndoUnit that was added to give it a chance to merge/consolidate the information. This is really for scenarios where the same property is being set multiple times in a row such as when you drag the thumb of a slider (although in WPF 4.5 you also use something like the Delay property on the binding to defer updating the source property).
With regards to your questions, no only the last property change that was recorded is given a chance to merge with the next property change undo unit. The default implementation for the PropertyChangeUndoUnit is to update the internal value it holds if the property and target object being changed are the same. With regards to the collection changes the only scenario that the default CollectionChangeUndoUnit<T> handles is the case of a single item being added and then subsequently a remove it received. In that case the undo unit indicates that it should be removed from the history. You can provide your own UndoUnit objects (either directly by using the AddChange method of the UndoManager or by deriving a custom UndoUnitFactory and implementing the methods you want to handle) and provide your own implementation of the merge. Note though that as I mentioned the UndoManager will only give the leaf undo unit the opportunity to merge with the incoming undo unit.
thanks for the answer. I guess I can use the Suspend/Resume feature to get around a few issues if I know in advance that I would need som merge-like functionality when setting alternate properties.