Detecting that a model has changes?

Is there an easy way to detect when a model has changes? I saw the DiagramModel.IsModified property, but it doesn’t look like that raises a PropertyChanged event. Ideally what I’d like to do is bind the Diagram.Name to a text element and append an asterisk if the model has not been saved. Also I’d like to enable my save command only when the model has changes.

I’m using WPF and have set HasUndoManager to true. I’d prefer to not call UndoManager.Clear() since it throws off the undo stack in my application. (It’s a rather odd, very custom undo system. I’ve plugged GoXam’s undo system into it.)

Well, here is one demonstration of what you could do:

myDiagram.InitialLayoutCompleted += (s, e) => { model.IsModified = false; model.Changed += (snd, evt) => { if (evt.Change == ModelChange.CommittedTransaction && (evt.Data as String) != "Layout") { if (model.IsModified) this.Title = "Changed!"; else this.Title = "unmodified"; } else if (evt.Change == ModelChange.FinishedUndo || evt.Change == ModelChange.FinishedRedo) { var mgr = model.UndoManager; if (mgr.UndoEditIndex >= 0) this.Title = "Changed!"; else this.Title = "unmodified"; } }; };
But during the undo/redo process it isn’t clear to me whether you want to consider the model modified or not. If you think about saving the document, and if you don’t automatically saved on each undo or redo, you might want to think the model is always modified, regardless of the undo/redo state. But if you think about the state of the model data, you might want to think of the model as being not modified if the user has undone all the way back. That’s a decision you’ll need to make for your application. You may then want to change the code above when an undo or redo happens.