This project has moved and is read-only. For the latest updates, please go here.

Undo merging for a UpdateSourceTrigger=PropertyChanged textbox?

May 2, 2014 at 3:31 AM
Hi -

I have a textbox that is bound with UpdateSourceTrigger=PropertyChanged. The property it is bound to uses:
DefaultChangeFactory.Current.OnChanging(this, "Name", Name, value, "Name changed.");
The problem is, this creates an undo item every time I hit a letter. I want it to change/update the property and undo stack on each keystroke, yet merge consecutive undos so that performing an Undo will undo all changes to the textbox. Any idea how to achieve this?
Jul 30, 2014 at 4:02 AM
Hi @ses4j,

I know this reply is much overdue, but for the benefit of others, the "UndoBatch" provides some of what you need.

For example, when the user enters the textbox, you could call:
UndoRoot.BeginChangeSetBatch(string batchDescription, bool consolidateChangesForSameInstance)
This will start consolidating all subsequent changes into a single "batch". When the user leaves the textbox, you could call:
... which will stop collecting changes into that batch. Then when you issue an "Undo", muf will undo all the changes in the batch together.

There is also an optimization on the BeginChangeSetBatch(). If you pass "true" for the consolidateChangesForSameInstance, then the framework will only keep the first and the last changes since those are the only values needed to handle an undo / redo. This saves a bit on memory.