[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Collapse]WPF Controls
 [Expand]What's Installed
 [Expand].NET Core 3 Support
 [Expand]Common Concepts
 [Expand]MVVM Framework
 [Collapse]Controls and Libraries
  [Expand]Data Grid
  [Expand]Ribbon, Bars and Menu
  [Expand]Charts Suite
  [Expand]Pivot Grid
  [Collapse]Rich Text Editor
   [Expand]Product Information
    Product Class Structure
    Supported Formats
   [Expand]Getting Started
   [Expand]RichEditControl Document
    Text Formatting
    Import and Export
   [Expand]Page Layout
    Mail Merge
    Restrictions and Protection
   [Expand]Visual Elements
    HTML Tag Support
    [Expand]UI Customization
    [Expand]Text Boxes
    [Expand]Document Elements
      How to: Insert a Field to a Document
      How to: Create a Table of Contents
      How to: Create TOC for Special Cases
      How to: Create a Table of Contents in Code
      How to: Handle the HyperlinkClick Event to Invoke the Custom Form
      How to: Use the Visitor-Iterator Pattern to Retrieve the List of Document Fonts
      How to: Highlight Document Syntax
      How to: Insert Dynamic Content
     Spell Check
  [Expand]Tree List
  [Expand]Gauge Controls
  [Expand]Map Control
  [Expand]Layout Management
  [Expand]Windows Modern UI
  [Expand]Data Editors
  [Expand]Navigation Controls
  [Expand]Spell Checker
  [Expand]Property Grid
  [Expand]PDF Viewer
  [Expand]TreeMap Control
  [Expand]Gantt Control
  [Expand]Diagram Control
  [Expand]Windows and Utility Controls
   Dialogs, Notifications and Panels
  [Expand]Scheduler (legacy)
 [Expand]Scaffolding Wizard
  Redistribution and Deployment
  Get More Help
 [Expand]API Reference
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Report and Dashboard Server
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

How to: Use the Visitor-Iterator Pattern to Retrieve the List of Document Fonts

You can use DocumentIterator and DocumentVisitor objects to retrieve all fonts used in the document and display them in the ListBoxEdit, as shown below:

Follow the steps below to complete this task:

  1. Declare the DocumentVisitorBase class descendant. The DocumentVisitorBase implements the IDocumentVisitor interface. This interface provides the Visit method overloads for every document element type.

    Create the Fonts property to return the list of fonts retrieved by the Visitor.

    Override the corresponding IDocumentVisitor.Visit method to retrieve the DocumentText element's FontName (see ReadOnlyTextPropertiesBase.FontName) value and add it to the fonts' list.


    You cannot remove the visited element's content or add a new content.

  2. In the main class, declare new Visitor class's object.

  3. Create a DocumentIterator class object. Pass true to the Iterator constructor as the visibleTextOnly parameter to skip hidden content.

  4. Call the DocumentIterator.MoveNext method to process each element, and use the IDocumentElement.Accept method to allow the Visitor to access the retrieved entity (returned by the DocumentIterator.Current property). When the IDocumentElement.Accept method returns returns false, the iterator has reached the end of the document. As a result, the Visitor executes the related Visit method for every iterated element.


    Pass one of the DocumentElementType (see DocumentElementType) values as a parameter to the DocumentIterator.MoveNext method to check a specific type of elements.

  5. Pass the retrieved fonts' list as the BaseListBoxEdit.ItemsSource property value to display the list the ListBoxEdit.

  6. Some elements, such as DocumentTextBox or DocumentCommentElement, can contain other elements. Create a new visitor and iterator instance in the corresponding Visit method to get these entities' content. Use DocumentTextBox.GetIterator or DocumentCommentElement.GetIterator method to provide a new iterator with access to the element's content. Pass true as the method's visibleTextOnly parameter to skip the hidden content.


    The iterator obtains only the main body's elements. The header's or footer's entities are not accessible to it.

Expanded See Also

Is this topic helpful?​​​​​​​