Undo refresh

I have Undo and redo buttons that are bound to CommandHandler.UndoCommand & RedoCommand.I also have a save button in my dialog, clicking on this button persists the state into database and I don’t want the user to call Undo on the diagram for any changes prior to this point so as part of saving I call UndoManager.Clear() on the model to clear all the edits.

After calling UndoManager.Clear my Undo button still stays Enabled till I go select or unselect a node in the diagram. I have tried calling CommandManager.InvalidateRequerySuggested() after UndoManager.Clear but that did not fix it either.

Any ideas how I can refresh the state of Undo Button.

You could try:

var cmd = myDiagram.CommandHandler.UndoCommand;
if (cmd.CanExecuteChanged != null) cmd.CanExecuteChanged(myDiagram, EventArgs.Empty);