Rich Text Editor for WPF - How to Use the Document Iterator and Visitor to Iterate Over Document Elements
This example creates a DocumentIterator instance for the current document and calls its MoveNext method to iterate over document elements. A Visitor
pattern is implemented to process a document element. The implementation is done by calling each element's Accept method with the MyVisitor
object instance as a parameter. MyVisitor
is a custom class that descends from the DocumentVisitorBase
class. MyVisitor
class contains a method that processes DocumentText elements to enclose Bold text in asterisks and return all characters without formatting. Paragraph ends are replaced with newline symbols, other document elements are skipped.
You can customize the MyVisitor
class to perform any operation with any type of element that the DocumentIterator
encounters.