static void OnIsModifiedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { TextEditor editor = d as TextEditor; if (editor != null) { TextDocument document = editor.Document; if (document != null) { UndoStack undoStack = document.UndoStack; if ((bool)e.NewValue) { if (undoStack.IsOriginalFile) undoStack.DiscardOriginalFileMarker(); } else { undoStack.MarkAsOriginalFile(); } } } }