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

disable recording

Feb 17, 2012 at 5:43 PM

is there a way of disable recording of changes for a service?
I don't need Undo and Redo all time, I just want to enable and disable it on demand.


Feb 17, 2012 at 6:05 PM

I have added a new Property to ISupportUndo called RecordsChanges and changed the following in DefaultChangeFactory

public static void OnChanging(object instance, string propertyName, object oldValue, object newValue, string descriptionOfChange)
	var supportsUndo = instance as ISupportsUndo;
	if (null == supportsUndo || !supportsUndo.RecordChanges)

	var root = supportsUndo.GetUndoRoot();
	if (null == root)

	Change change = GetChange(instance, propertyName, oldValue, newValue);

	UndoService.Current[root].AddChange(change, descriptionOfChange);

Feb 17, 2012 at 7:50 PM
Edited Feb 17, 2012 at 7:55 PM

Hello @gnauck,

I think that this feature might already be in MUF. There is an interface called "IUndoMetadata" that you can implement on your objects. This interface has the methods "CanUndoProperty" and "CanUndoCollectionChange" that allow you to indicate whether the property should be tracked for undo.

The DefaultChangeFactory calls these inside of it's GetChange() method. If the they return false, then no change is generated.

Is this what you were looking for?

- Nathan

Feb 17, 2012 at 7:59 PM
Edited Feb 17, 2012 at 8:01 PM

I just checked in some changes to the unit tests to show how this works. Look for the unit test named "UndoRoot_Can_Undo_the_Last_ChangeSet_With_Conditional_Undo_On_A_Property". Then look at the implementation of ChildA. It implements IUndoMetadata.

- Nathan

Feb 17, 2012 at 8:22 PM

yes thanks, this is what I am looking for.