# Fields

Fields are a convenient way to show non-static data in the document. In this way, you could present different data to the end-user without actually changing the document content.

This topic contains the following sections:

* [Field Types](https://www.telerik.com/products/wpf/documentation/controls/radrichtextbox/features/fields-and-document-variables/fields#field-types)

* [Display Modes](https://www.telerik.com/products/wpf/documentation/controls/radrichtextbox/features/fields-and-document-variables/fields#display-modes)

* [Inserting a Field](https://www.telerik.com/products/wpf/documentation/controls/radrichtextbox/features/fields-and-document-variables/fields#inserting-a-field)

* [Updating a Field](https://www.telerik.com/products/wpf/documentation/controls/radrichtextbox/features/fields-and-document-variables/fields#updating-a-field)

* [Updating all Fields](https://www.telerik.com/products/wpf/documentation/controls/radrichtextbox/features/fields-and-document-variables/fields#updating-all-fields)

## Field Types

In the model of RadDocument, the base class for all fields is **CodeBasedField**. It is an abstract class that can be inherited from.

> All the supported field codes and switches for them are listed in the [Supported Fields](https://www.telerik.com/products/wpf/documentation/controls/radrichtextbox/features/fields-and-document-variables/supported-fields) topic.

## Display Modes

Fields normally have two modes – **Code** and **Result**. When in code mode, they appear as {\<FieldTypeName> \[\<field parameter>] \[\<switch> \<switch parameter>]}.

For instance, Page Fields appear as { PAGE }, Merge Fields as { MERGEFIELD FirstName } or { MERGEFIELD FirstName \b "text that will appear before the merge field if it is not empty" }.

In result mode, all fields get evaluated depending on some conditions – the place in the document where they appear in the case of page fields, the current mail merge record for merge fields, etc.

**MergeFields** have one additional mode – **DisplayName** that shows the property path they use in brackets of the type <<\[PropertyPathHere]>>. Furthermore, there are specific methods and commands of the editor that change the display mode of merge fields or even remove them from the document altogether, replacing them with the ResultFragment. More information on this topic can be found in the [Mail Merge](https://www.telerik.com/products/wpf/documentation/controls/radrichtextbox/features/mail-merge/mail-merge) article.

## Inserting a Field

Inserting any type of field in the document of an editor can be done with the **InsertField()** method.

Insert a page field:

```C#
    this.radRichTextBox.InsertField(new PageField());
```

## Updating a Field

Update of a field can be triggered from the context menu or using the **UpdateField()** method by passing the corresponding FieldRangeStart of the field as a parameter.

Update a field:

```C#
    this.radRichTextBox.UpdateField(fieldRangeStart);
```

## Updating all Fields

You can update all fields in the document with the **UpdateAllFields()** method of **RadRichTextBox**. The method is optimized to perform better than updating fields one by one using the **Update** method.

> tip Correctly updating all fields in a document works in almost all cases, but it’s not always possible as there are multiple dependencies between the fields. You can influence the way UpdateAllFields is executed by registering additional [update information for specific field types](https://www.telerik.com/products/wpf/documentation/controls/radrichtextbox/features/fields-and-document-variables/custom-fields#integrating-with-updateallfields-operation).

## See Also

* [Supported Field Codes](https://www.telerik.com/products/wpf/documentation/controls/radrichtextbox/features/fields-and-document-variables/supported-fields)
* [Custom Fields](https://www.telerik.com/products/wpf/documentation/controls/radrichtextbox/features/fields-and-document-variables/custom-fields)
* [Mail Merge](https://www.telerik.com/products/wpf/documentation/controls/radrichtextbox/features/mail-merge/mail-merge)
* [CustomField SDK example](https://github.com/telerik/xaml-sdk/tree/master/RichTextBox/CustomField)
