# Content Controls

> Load MS Word content controls and legacy form fields into the WPF TextControl, then read, change and create them with FormCheckBox, FormText and field adapters.

- **Product:** TX Text Control .NET for WPF
- **Section:** Documentation
- **Kind:** Topic
- **Path:** TX Text Control .NET for WPF > Document Processing > Content Controls
- **5042 words**
- **Web URL:** https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/content-controls/
- **LLMs URL:** https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/content-controls/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/content-controls/llms-full.txt

---

A form built in MS Word, such as an order form or a checklist, holds its input elements as content controls or, in older documents, as legacy form fields. When such a DOCX file is loaded into the WPF `TextControl`, one load setting decides whether they become TX Text Control form fields, whose values are easy to read and set, or MS Word fields that keep Word's own settings, such as the title and tag of a content control. The field adapter classes of `TXTextControl.DocumentServer.Fields` read and write those settings and create new content controls in code.

The code goes into *MainWindow.xaml.cs* of a window with a `TextControl` named `textControl1` and a `TextBlock` named `statusText`. Form fields created in TX Text Control are covered in [Forms and Conditional Instructions](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/form-fields/llms-full.txt), and the other kinds of MS Word fields in [Fields and Subtext Parts](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/fields/llms-full.txt).

*MainWindow.xaml.cs* needs these `using` directives:

```csharp
using System;
using System.Text;
using System.Windows;
using TXTextControl;
using TXTextControl.DocumentServer.Fields;
```

### What Content Controls and Legacy Form Fields Are

MS Word offers two kinds of input elements for forms:

- **Content controls**, introduced with MS Word 2007, include rich text, plain text, picture, combo box, drop-down list, check box and date picker controls. Only DOCX files store them; the MS Word 97-2003 format doesn't.
- **Legacy form fields** are the older text box, check box and drop-down list fields, stored as the fields `FORMTEXT`, `FORMCHECKBOX` and `FORMDROPDOWN`.

TX Text Control supports both. [LoadSettings.ApplicationFieldFormat](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/loadsettings/applicationfieldformat-property/llms-full.txt) decides what they become when a document is loaded:

| `ApplicationFieldFormat` | Content controls and legacy form fields become | Other MS Word fields become |
|---|---|---|
| `None` (default) | Form fields in [TextControl.FormFields](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/formfields-property/llms-full.txt) | Not imported as fields |
| `MSWordTXFormFields` | Form fields in `FormFields` | Application fields |
| `MSWord` | Application fields in [TextControl.ApplicationFields](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/applicationfields-property/llms-full.txt) | Application fields |

An [ApplicationField](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/applicationfield/llms-full.txt) gives access to the [TypeName](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/applicationfield/typename-property/llms-full.txt) and the [Parameters](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/applicationfield/parameters-property/llms-full.txt) of a Word field. For content controls and legacy form fields, the parameters are Office Open XML markup. Every content control has the type name `SDTBLOCK`, and its markup names the kind of control. The adapters described below read and write this markup for you.

### Read the Values of a Word Form

To read the values that users entered in MS Word, load the form as form fields. This handler opens *order-form.docx* and lists each field with its value:

```csharp
private void ReadWordForm_Click(object sender, RoutedEventArgs e)
{
    LoadSettings loadSettings = new LoadSettings()
    {
        // Content controls and legacy form fields become form fields
        ApplicationFieldFormat = ApplicationFieldFormat.MSWordTXFormFields
    };

    textControl1.Load("order-form.docx", StreamType.WordprocessingML, loadSettings);

    StringBuilder values = new StringBuilder();

    foreach (FormField field in textControl1.FormFields)
    {
        switch (field)
        {
            case CheckFormField checkBox:
                values.AppendLine($"{checkBox.Name}: {(checkBox.Checked ? "checked" : "not checked")}");
                break;

            case DateFormField dateField:
                values.AppendLine($"{dateField.Name}: {dateField.Date?.ToShortDateString() ?? "(no date)"}");
                break;

            default:
                // Text boxes, combo boxes and drop-down lists show their value as text
                values.AppendLine($"{field.Name}: {field.Text}");
                break;
        }
    }

    statusText.Text = values.ToString();
}
```

A check box content control of the Word form arrives as a [CheckFormField](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/checkformfield/llms-full.txt), and its [Checked](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/checkformfield/checked-property/llms-full.txt) property is the state the user set in MS Word. A date picker becomes a [DateFormField](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/dateformfield/llms-full.txt) whose [Date](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/dateformfield/date-property/llms-full.txt) is `null` when no date was entered. Setting these properties and saving the document as DOCX fills the form; [Forms and Conditional Instructions](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/form-fields/llms-full.txt) shows the other members of the form field classes.

### How Field Adapters Work

A field adapter wraps an application field and turns its markup into typed properties: passed an existing application field, it reads and changes that field; created without a parameter, it makes a new field that [ApplicationFieldCollection.Add](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/applicationfieldcollection/add-method/llms-full.txt) inserts. [Use Field Adapters for MS Word Fields](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/fields/#use-field-adapters-for-ms-word-fields) explains both directions and how the constant [TYPE\_NAME](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-documentserver-fields/fieldadapter/type-name-field/llms-full.txt) chooses the adapter. These adapters handle the form elements of MS Word:

| Adapter | Base class | Wraps | Typed properties |
|---|---|---|---|
| [FormText](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-documentserver-fields/formtext/llms-full.txt) | [FormFieldAdapter](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-documentserver-fields/formfieldadapter/llms-full.txt) | A legacy text box | [MaxLength](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-documentserver-fields/formtext/maxlength-property/llms-full.txt), [Format](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-documentserver-fields/formtext/format-property/llms-full.txt), [Type](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-documentserver-fields/formtext/type-property/llms-full.txt) (regular text, number, date, current date, current time or calculation) |
| [FormCheckBox](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-documentserver-fields/formcheckbox/llms-full.txt) | `FormFieldAdapter` | A legacy check box, `FORMCHECKBOX` | [Checked](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-documentserver-fields/formcheckbox/checked-property/llms-full.txt), [Size](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-documentserver-fields/formcheckbox/size-property/llms-full.txt), [SizeAuto](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-documentserver-fields/formcheckbox/sizeauto-property/llms-full.txt) |
| [FormDropDown](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-documentserver-fields/formdropdown/llms-full.txt) | `FormFieldAdapter` | A legacy drop-down list, `FORMDROPDOWN` | [ListEntries](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-documentserver-fields/formdropdown/listentries-property/llms-full.txt) |
| [PlainTextContentControl](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-documentserver-fields/plaintextcontentcontrol/llms-full.txt), [RichTextContentControl](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-documentserver-fields/richtextcontentcontrol/llms-full.txt) | [ContentControlFieldAdapter](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-documentserver-fields/contentcontrolfieldadapter/llms-full.txt) | A plain text or rich text content control | [Text](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-documentserver-fields/plaintextcontentcontrol/text-property/llms-full.txt) |
| [CheckBoxContentControl](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-documentserver-fields/checkboxcontentcontrol/llms-full.txt) | `ContentControlFieldAdapter` | A check box content control | [Checked](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-documentserver-fields/checkboxcontentcontrol/checked-property/llms-full.txt) |
| [ComboBoxContentControl](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-documentserver-fields/comboboxcontentcontrol/llms-full.txt), [DropDownListContentControl](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-documentserver-fields/dropdownlistcontentcontrol/llms-full.txt) | `ContentControlFieldAdapter` | A combo box or drop-down list content control | [ListItems](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-documentserver-fields/comboboxcontentcontrol/listitems-property/llms-full.txt) of the combo box, [ListItems](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-documentserver-fields/dropdownlistcontentcontrol/listitems-property/llms-full.txt) of the drop-down list |
| [DateContentControl](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-documentserver-fields/datecontentcontrol/llms-full.txt) | `ContentControlFieldAdapter` | A date picker content control | [Date](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-documentserver-fields/datecontentcontrol/date-property/llms-full.txt), [DateFormat](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-documentserver-fields/datecontentcontrol/dateformat-property/llms-full.txt), [LanguageID](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-documentserver-fields/datecontentcontrol/languageid-property/llms-full.txt), [Calendar](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-documentserver-fields/datecontentcontrol/calendar-property/llms-full.txt), [StoreMappedDataAs](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-documentserver-fields/datecontentcontrol/storemappeddataas-property/llms-full.txt) |

### Read and Change Legacy Form Fields

Loaded with `ApplicationFieldFormat.MSWord`, legacy form fields keep their Word settings, such as the help text shown for a field. This handler lists the legacy form fields of *order-form.docx* and checks every check box:

```csharp
private void ReadLegacyFormFields_Click(object sender, RoutedEventArgs e)
{
    LoadSettings loadSettings = new LoadSettings()
    {
        // All MS Word fields, form fields included, become application fields
        ApplicationFieldFormat = ApplicationFieldFormat.MSWord
    };

    textControl1.Load("order-form.docx", StreamType.WordprocessingML, loadSettings);

    StringBuilder list = new StringBuilder();

    foreach (ApplicationField field in textControl1.ApplicationFields)
    {
        if (field.TypeName == FormCheckBox.TYPE_NAME)
        {
            FormCheckBox checkBox = new FormCheckBox(field);
            checkBox.Checked = true;
            list.AppendLine($"Check box {checkBox.Name}, help text: {checkBox.HelpText}");
        }
        else if (field.TypeName == FormDropDown.TYPE_NAME)
        {
            FormDropDown dropDown = new FormDropDown(field);
            list.AppendLine($"Drop-down list {dropDown.Name}: {string.Join(", ", dropDown.ListEntries)}");
        }
        else if (field.TypeName == FormText.TYPE_NAME)
        {
            FormText textBox = new FormText(field);
            list.AppendLine($"Text box {textBox.Name}: {textBox.Text} (up to {textBox.MaxLength} characters)");
        }
    }

    statusText.Text = list.ToString();
}
```

The code works as follows:

- `TYPE_NAME` of [FormCheckBox](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-documentserver-fields/formcheckbox/constructor/llms-full.txt), `FormDropDown` and `FormText` is compared with the type name of each field, so the code doesn't depend on how the type names are spelled.
- The constructor with an application field connects the adapter to the field in the document. Setting [Checked](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-documentserver-fields/formcheckbox/checked-property/llms-full.txt) changes that field.
- [Name](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-documentserver-fields/formfieldadapter/name-property/llms-full.txt), [Text](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-documentserver-fields/formfieldadapter/text-property/llms-full.txt) and [HelpText](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-documentserver-fields/formfieldadapter/helptext-property/llms-full.txt) belong to the base class `FormFieldAdapter`, which also has [StatusText](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-documentserver-fields/formfieldadapter/statustext-property/llms-full.txt), [Enabled](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-documentserver-fields/formfieldadapter/enabled-property/llms-full.txt), [CalcOnExit](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-documentserver-fields/formfieldadapter/calconexit-property/llms-full.txt), [Font](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-documentserver-fields/formfieldadapter/font-property/llms-full.txt) and [Bounds](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-documentserver-fields/formfieldadapter/bounds-property/llms-full.txt), in twips.
- The `ApplicationFields` collection contains the fields of the text part with the input focus. For forms with fields in headers, footers or text frames, loop through [TextParts](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/textparts-property/llms-full.txt) as [Fields and Subtext Parts](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/fields/#find-the-fields-of-all-text-parts) shows.

Save the document with `StreamType.WordprocessingML` to keep the changed fields as MS Word form fields.

### Create Content Controls in Code

The content control adapters create content controls that MS Word shows with their title and tag. This handler inserts a plain text control for the customer name, a date picker for the order date and a check box for the terms, each at the input position:

```csharp
private void InsertContentControls_Click(object sender, RoutedEventArgs e)
{
    textControl1.Text = "";

    textControl1.Selection.Text = "Customer: ";
    PlainTextContentControl customerName = new PlainTextContentControl()
    {
        Title = "Customer name",
        Tag = "CustomerName",
        Text = "Acme Corporation"
    };
    textControl1.ApplicationFields.Add(customerName.ApplicationField);

    textControl1.Selection.Text = "\r\nOrder date: ";
    DateContentControl orderDate = new DateContentControl()
    {
        Title = "Order date",
        Tag = "OrderDate",
        Date = DateTime.Today
    };
    textControl1.ApplicationFields.Add(orderDate.ApplicationField);

    textControl1.Selection.Text = "\r\nI accept the terms: ";
    CheckBoxContentControl termsAccepted = new CheckBoxContentControl()
    {
        Title = "Terms accepted",
        Tag = "TermsAccepted",
        Checked = false
    };
    textControl1.ApplicationFields.Add(termsAccepted.ApplicationField);

    // DOCX is the format that keeps content controls
    textControl1.Save("order-form.docx", StreamType.WordprocessingML);
}
```

The code works as follows:

- Each adapter is created with its constructor without parameters, such as the [PlainTextContentControl constructor](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-documentserver-fields/plaintextcontentcontrol/constructor/llms-full.txt), which creates a new application field.
- [ApplicationFieldCollection.Add](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/applicationfieldcollection/add-method/llms-full.txt) inserts the field at the input position, and the next `Selection.Text` continues behind it.
- Opened in MS Word, *order-form.docx* shows three content controls. Loaded again with the default load settings, they are form fields in the `TextControl`.

The base class [ContentControlFieldAdapter](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-documentserver-fields/contentcontrolfieldadapter/llms-full.txt) has the properties that all content controls share:

| Property | Contains |
|---|---|
| [Title](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-documentserver-fields/contentcontrolfieldadapter/title-property/llms-full.txt), [Tag](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-documentserver-fields/contentcontrolfieldadapter/tag-property/llms-full.txt) | The title that MS Word shows and the tag that code uses to find the control |
| [Id](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-documentserver-fields/contentcontrolfieldadapter/id-property/llms-full.txt) | The ID of the content control |
| [ContentEditable](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-documentserver-fields/contentcontrolfieldadapter/contenteditable-property/llms-full.txt), [ContentDeletable](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-documentserver-fields/contentcontrolfieldadapter/contentdeletable-property/llms-full.txt) | Whether the content can be edited and deleted |
| [Type](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-documentserver-fields/contentcontrolfieldadapter/type-property/llms-full.txt) | The type of the content control |
| [Placeholder](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-documentserver-fields/contentcontrolfieldadapter/placeholder-property/llms-full.txt) | The placeholder part of the content control |

To change a content control of an existing document, load it with `ApplicationFieldFormat.MSWord` and pass its application field to the constructor of the adapter of its kind, for example `new CheckBoxContentControl(field)`. The blog article [Working with Content Controls in MS Word Documents using TX Text Control in C#](https://www.textcontrol.com/blog/2024/03/04/working-with-content-controls-in-ms-word-documents-using-tx-text-control-in-c-sharp/) shows the import options side by side; its code uses `ServerTextControl`, whose collections are the same as those of the WPF `TextControl`.

### Merge Data Into Word Forms

A form template can also be filled by a mail merge. [MailMerge.FormFieldMergeType](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-documentserver/mailmerge/formfieldmergetype-property/llms-full.txt) decides whether form fields keep their input elements with the merged values preselected or are replaced with the values; [Merge Fields](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/fields/llms-full.txt) describes the options.

### Next Steps

- [Forms and Conditional Instructions](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/form-fields/llms-full.txt): create, protect and validate forms with TX Text Control form fields.
- [Fields and Subtext Parts](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/fields/llms-full.txt): the other MS Word fields and their adapters.
- [Form Fields and Conditional Instructions](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-editor/form-fields/llms-full.txt): design forms with the Form Fields ribbon tab.
- [PDF Forms](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/pdf/forms/llms-full.txt): turn the form into a fillable PDF.

---

## Nearby

- **Previous:** [Conditional Instructions](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/conditional-instructions/llms-full.txt)
- **Next:** [Mail Merge and Reporting](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/mail-merge/llms-full.txt)
