views:

138

answers:

1

As part of an editor project, I need to add functionality to the WPF RichTextBox control to allow the user to perform operations on a table. One of those operations is to apply a new width value to one or more columns of the table. I have a function that is applying a new Width value to the TableColumn objects in question, and the table is resizing itself nicely. However, I've noticed that the column-width change operation does not seem to be added to the undo stack.

In other words, if a user types something, then changes a column width, then selects undo, the RichTextBox control undoes the user's typing. Undo and redo don't seem to be picking up the property change on the TableColumn object.

Is there some way to make this operation occur in a way that it actually is undoable/redoable?

A: 

Unfortunately, it appears that FlowDocument TableColumn objects are considered layout guidelines rather than true mandatory objects. As a result, changes to those objects are not tracked by the change tracking system build into the WPF RichTextBox control. See here for further details.

I worked around the problem by making table changes that involve TableColumn objects into atomic operations that would be tracked by the change tracking system. Basically, if I want to perform an operation that involved manipulating TableColumn objects, I began a grouped undo operation, removed the enclosing Table from the FlowDocument, manipulated it as needed, added it back to the FlowDocument, then closed the undo batch. This way, the change tracking system record a replacement of existing content, which undo/redo can properly handle.

Jeff