UndoManager on/off

In my Application I have two Modes:
EditMode and WorkingMode.

Now I want that the UndoManager is working only in EditMode. Also there are Properties that the UndoManager should not be able to undo.

How can I do this?

It depends on whether you want to keep the UndoManager’s history across the times when the app is in “WorkingMode”.

If you do, when going into “WorkingMode” remember the value of DiagramModel.UndoManager and then set that property to null. To go back into “EditMode”, set DiagramModel.UndoManager back to the saved UndoManager.

If you don’t, you can toggle DiagramModel.HasUndoManager. Alternatively, you can go into “EditMode” either using a new UndoManager, or you can call UndoManager.Clear() on the old one.

To have the UndoManager temporarily avoid recording changed events (ModelChangedEventArgs), you can temporarily set DiagramModel.SkipsUndoManager to true. This is typically done in some command or during the execution of some event handler that is invoked during a transaction. Be sure to remember the old value, so that you can restore it to the original value, in case of nested calls that need “skipping”.

The last one sounds good, I can do this in the EditCommand.

You might be misunderstanding me. You can only temporarily turn on SkipsUndoManager, and then reset it to its original value, within a transaction (including the implementation of a command).

Ok, I really missunderstood. Then I will do it the other way.