public void Undo() { var textEditor = (TextEditor)textAreaReference.Target; if (textEditor != null) { textEditor.CaretIndex = caretPosition; textEditor.SelectionStart = selectionStart; textEditor.SelectionEnd = selectionEnd; } }