Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1735
Merging feature documentation
posted

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

  • 54937
    Verified Answer
    Offline posted

    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.