[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
    [Expand]Field Codes
    [Expand]Format Switches
    Text Formatting
    Import and Export
   [Expand]Page Layout
    Track Changes
    Mail Merge
    Restrictions and Protection
   [Expand]Visual Elements
    HTML Tag Support
  [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)


This topic consists the following sections:

Expanded Overview

The Field is a set of codes that instructs the RichEditControl to insert text or graphics into a document automatically. The field code syntax is illustrated and described below.

  • Field Name - the name of the current field. Refer to the Field Codes section for a list of all available fields.
  • Property - instruction/variable used in a particular field. This is an optional element.
  • Switch - an additional parameter that offers more information. This is an optional element. Refer to the Format Switches section for a list of supported format switches.

The RichEditControl supports the following field types:

  1. Non-MailMerge

    Regular fields used to insert a simple data, such as DATE, TIME or PAGE. The Non-MailMerge field results are shown after the update.

  2. MailMerge

    Fields used in the Mail Merge process. They get a value only if there is a mail merge data source bound to the RichEditControl. In the resulting document, MailMerge fields are evaluated and substituted with the resulting values.

  3. Mixed

    Fields which do not require a data source to get its value, such as INCLUDEPICTURE and DOCVARIABLE They are substituted with the resulting values during mail merge.


    You can use the DOCVARIABLE field to insert formatted strings or content from the RichEditDocumentServer (see RichEditDocumentServer) or SubDocument (see SubDocument) objects. Refer to the How to: Insert Dynamic Content topic for a code sample.

  4. Formula

    The = (Formula) field is a code that uses mathematical formulas and numeric field values to calculate a number. The formula field syntax looks as follows:


    The RichEditControl supports the following operators in the formula field:

    • Addition (+)
    • Subtraction (-)
    • Multiplication (*)
    • Division (/)
    • Powers and Roots (^)
    • Equal to (=)
    • Less than (<)
    • Less than or equal to (<=)
    • Greater than (>)
    • Greater than or equal to (>=)
    • Not equal to (<>)

    You can change the field's numeric format. Refer to the Numeric Format Switch topic for a list of available format switches.

Expanded Insert and Modify Fields

Members from the table below allow you to insert and modify the field programmatically.

Member Description
SubDocument.BeginUpdate Opens the document for editing.
DocumentPosition.BeginUpdateDocument Opens the document raleted to the current position for editing.
FieldCollection.Create Creates a new Field object.
SubDocument.Fields Provides access to the collection of fields in the current document.
Field.CodeRange Gets the range containing the field codes.
Field.ResultRange Gets the range containing the field result.
SubDocument.InsertText Inserts the specified text at the specified position.
SubDocument.EndUpdate Finalizes the modification.

A complete sample project is available at https://github.com/DevExpress-Examples/wpf-richedit-document-api-t213968.


You can insert the desired field to the document header or footer. Use the Section.BeginUpdateHeader - Section.EndUpdateHeader or Section.BeginUpdateFooter - Section.EndUpdateFooter paired methods to obtain the header or footer.

Expanded Update Fields

Most fields are updated automatically when the document is saved or printed, or during the mail merge operation. Use the Field.Update method to update the field on demand. Specify the UpdateField property to set what document fields should be updated automatically when loading the document, as shown in the code snippet below:

Set the field's Field.Locked property to true to prevent a specific field from being updated. Use the DXRichEditFieldOptions.UpdateLockedFields option to allow updating locked fields.

The DOCVARIABLE field is not updated during mail merge or document insertion. Handle the RichEditControl.CalculateDocumentVariable event to update the DOCVARIABLE fields' values.

The RichEditControl.CalculateDocumentVariable event does not occur for a locked DOCVARIABLE field, and the field value remains unchanged. Set the DXRichEditFieldOptions.UpdateLockedFields option to the UpdateLockedFields.DocVariableOnly value to update DOCVARIABLE fields.


A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=e3282.

Expanded Field Options

Use the Field.ShowCodes property to change the target field's display mode.


A complete sample project is available at https://github.com/DevExpress-Examples/wpf-richedit-document-api-t213968.


You can also use ShowAllFieldCodesCommand or ShowAllFieldResultsCommand commands to change the fields' display mode.

Use the RichEditControl.FieldOptions property to specify how RichEditControl should process and display document fields, as shown in the code snippet below:

Set the DXRichEditDocumentCapabilitiesOptions.Fields property to DocumentCapability.Hidden or DocumentCapability.Disabled to restrict inserting fields to the document.

Expanded Operate Fields in the User Interface

To simplify many common tasks when working with fields, the Rich Editor UI provides the following commands and shortcuts:

Task UI Command / Shortcut Key
Insert a field Press CTRL+F9.
Show field codes Press ALT+F9 or click the Show All Field Codes button in the Mail Merge ribbon tab or bar group.
Update field values Select a range containing fields and press F9.
Show spaces and formatting marks Press CTRL+SHIFT+8.

End users can update or toggle the code of the document field from the context menu or by using the Mail Merge ribbon tab. Refer to the Lesson 1 - Create a Simple Rich Text Editor topic for details on how to provide a Ribbon UI for the RichEditControl.

MERGEFIELD Display Modes

When the Show All Field Results button is clicked (or the ShowAllFieldResultsCommand is executed), the MERGEFIELD field is shown as a placeholder:

End users can click View Merged Data to display the MERGEFIELD code result:

Set the DXRichEditMailMergeOptions.ViewMergedData to true or execute the ToggleViewMergedDataCommand command to achieve this task programmatically.

Expanded See Also

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