# WPF.TextControl

> Declare WPF.TextControl in XAML, choose the view and edit mode, handle Loaded and Changed, and load and save DOCX files: the editor's key members and events.

- **Product:** TX Text Control .NET for WPF
- **Section:** Documentation
- **Kind:** Topic
- **Path:** TX Text Control .NET for WPF > Overview > Components > WPF.TextControl
- **2602 words**
- **Web URL:** https://docs.textcontrol.com/tx-text-control-dotnet-wpf/overview/components/textcontrol/
- **LLMs URL:** https://docs.textcontrol.com/tx-text-control-dotnet-wpf/overview/components/textcontrol/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-text-control-dotnet-wpf/overview/components/textcontrol/llms-full.txt

---

In a WPF application, the editor your users type in is `TXTextControl.WPF.TextControl`: an element you declare in the XAML of a window, next to buttons, menus and panels. Read on for what the class is, how it gets into a window, which of its properties and events you use first, and where it differs from `ServerTextControl`.

### What WPF.TextControl Is

[TextControl](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/llms-full.txt) in the `TXTextControl.WPF` namespace is a WPF control with word processing features, derived from `System.Windows.Controls.Control`. It is not the Windows Forms class of the same name: the WPF product has its own `TextControl`, with WPF types such as `System.Windows.Point` and `System.Windows.Controls.PageRange` in its signatures. The reference lists the members the class defines; `Width`, `Margin`, `Visibility` and the other inherited members are documented by Microsoft.

The control is built from a template, whose parts show the document in a `ScrollViewer`; [The Template of the TextControl](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-editor/ribbon-ui/themes/#the-template-of-the-textcontrol) describes them.

The objects a document consists of are not WPF classes. `Selection`, `Table`, `Image`, `HeaderFooter`, `FormField` and the other classes of the document live in the `TXTextControl` namespace and are the same ones that [ServerTextControl](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/overview/components/servertextcontrol/llms-full.txt) uses. Code that formats text or fills a table therefore works in the editor and in the background alike.

Some properties are WPF dependency properties, among them [ZoomFactor](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/zoomfactor-property/llms-full.txt), [IsUndoEnabled](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/isundoenabled-property/llms-full.txt), [FontFamily](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/fontfamily-property/llms-full.txt) and [HorizontalScrollBarVisibility](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/horizontalscrollbarvisibility-property/llms-full.txt). Like the properties of other WPF controls, you set them in XAML, in a style or through a binding.

### What You Do With It

- **Give users a word processor.** Users type, select, copy and paste, undo and redo, and format characters and paragraphs with the keyboard and the mouse.
- **Change the document in code.** The [Selection](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/selection-property/llms-full.txt) property formats the selected text, and collections such as [Tables](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/tables-property/llms-full.txt), [Images](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/images-property/llms-full.txt) and [HeadersAndFooters](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/headersandfooters-property/llms-full.txt) return the elements of the document.
- **Open and save files** in DOCX, RTF, HTML, PDF and the other [supported formats](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/overview/file-formats/llms-full.txt), through the built-in **Open** and **Save As** dialog boxes or from a file, a stream, a byte array or a string.
- **Collaborate and protect.** Comments, tracked changes, editable regions and document permissions are part of the editor.
- **Print** the document with the standard print dialog of Windows, or directly to a printer you name.

The ribbon tabs, the button bar, the rulers, the status bar and the sidebar are separate controls. See [Ribbon Tabs, Toolbars, Rulers, and Status Bar](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/overview/components/ribbon-toolbars/llms-full.txt) and [Sidebar](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/overview/components/sidebar/llms-full.txt).

### Declare It in XAML

The `TextControl` is an item of the toolbox tab **TX Text Control 34.0**, and in XAML it is an element such as `<WPF:TextControl x:Name="textControl1" />`, with the prefix that the window declares for the namespace `TXTextControl.WPF`. Placed as the last child of a `DockPanel`, the editor fills the space that the bars around it leave:

![A WPF window in the Visual Studio designer with a button bar and a horizontal ruler at the top, a vertical ruler at the left, an empty page in the middle and a status bar at the bottom.](https://docs.textcontrol.com/assets/img/tx-text-control-dotnet-wpf/designer-bars-rulers.294c1249.webp)

[Create Your First WPF Application](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/getting-started/document-editor/first-application/llms-full.txt) builds this window step by step, and [Add TextControl in XAML](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/getting-started/document-editor/xaml/llms-full.txt) explains the XAML.

### How You Work With It

#### Choose How the Document Is Displayed

[ViewMode](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/viewmode-property/llms-full.txt) decides whether the control shows pages with headers and footers, text formatted by the page size without pages, or text as wide as the control; [Choose a View Mode](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-editor/viewing/#choose-a-view-mode) describes each value. [PageSize](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/pagesize-property/llms-full.txt) and [PageMargins](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/pagemargins-property/llms-full.txt) use the unit that [PageUnit](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/pageunit-property/llms-full.txt) selects: `Millimeter`, `CentiInch` (1/100 inch), `Twips` (1/1440 inch) or `StandardWPF`, the 1/96 inch that WPF measures in. `ZoomFactor` sets the zoom in percent.

#### Decide What Users May Change

[EditMode](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/editmode-property/llms-full.txt) controls editing. With `Edit`, users can change everything. With `ReadAndSelect`, they can select the text, and [DocumentPermissions](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/documentpermissions-property/llms-full.txt) decides what else they may do. With `ReadOnly`, the text is only displayed. [IsTrackChangesEnabled](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/istrackchangesenabled-property/llms-full.txt) records each change as a tracked change.

#### Work With the Content

- **The selection.** `Selection` is the current selection in the part of the document that has the input focus: the main text, a header or footer or a text frame. Its properties, such as `Bold` or `FontSize`, format the selected text.
- **The collections.** `Tables`, `Images`, [ApplicationFields](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/applicationfields-property/llms-full.txt), [Paragraphs](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/paragraphs-property/llms-full.txt) and [TrackedChanges](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/trackedchanges-property/llms-full.txt) refer to the part with the input focus, while [Sections](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/sections-property/llms-full.txt) and [FormFields](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/formfields-property/llms-full.txt) hold elements of the whole document.
- **The input position.** [InputPosition](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/inputposition-property/llms-full.txt) is the place where typed text appears.

#### Handle Its Events

The `Loaded` event that every WPF element raises is where the Text Control samples give the editor the keyboard focus and load their first document. The events of `TextControl` itself report what happens in the document: [Changed](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/changed-event/llms-full.txt) when the contents change, [InputPositionChanged](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/inputpositionchanged-event/llms-full.txt) when the input position moves, and [DocumentLoaded](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/documentloaded-event/llms-full.txt) after a document has been loaded. You connect them in XAML, like the events of any other element.

### Where Your Code Starts

The first code most applications write for the editor loads a document in the `Loaded` handler of the `TextControl`, because the control can't work with a document before WPF has loaded it into the window. [Load a Document When the Editor Is Ready](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/getting-started/document-editor/first-application/#load-a-document-when-the-editor-is-ready) shows this handler, and [Track Unsaved Changes](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-editor/events/#track-unsaved-changes) uses the `Changed` event to save only a document that has changed.

### Key Members

| Member | Purpose |
|---|---|
| [Load](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/load-method/llms-full.txt), [Save](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/save-method/llms-full.txt) | Load a document, replacing the contents, and save it, with or without a file dialog. |
| [Append](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/append-method/llms-full.txt) | Adds a document to the existing one. |
| [Selection](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/selection-property/llms-full.txt) | The current selection, which inserts and formats text. |
| [ViewMode](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/viewmode-property/llms-full.txt), [ZoomFactor](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/zoomfactor-property/llms-full.txt) | How the document is displayed and at which zoom. |
| [EditMode](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/editmode-property/llms-full.txt) | Whether the text can be edited, only selected or only read. |
| [Tables](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/tables-property/llms-full.txt), [Images](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/images-property/llms-full.txt), [HeadersAndFooters](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/headersandfooters-property/llms-full.txt) | The tables, images, headers and footers of the document. |
| [Comments](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/comments-property/llms-full.txt), [TrackedChanges](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/trackedchanges-property/llms-full.txt) | The comments and the tracked changes. |
| [Undo](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/undo-method/llms-full.txt), [Redo](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/redo-method/llms-full.txt) | Undo and redo the last action. `IsUndoEnabled` switches the undo buffer off, which saves time and memory when code generates a report. |
| [Cut](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/cut-method/llms-full.txt), [Copy](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/copy-method/llms-full.txt), [Paste](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/paste-method/llms-full.txt) | Clipboard operations. |
| [Find](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/find-method/llms-full.txt), [Replace](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/replace-method/llms-full.txt) | `Find` searches the text in code or opens the built-in Find dialog box; `Replace` opens the Replace dialog box. |
| [FontDialog](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/fontdialog-method/llms-full.txt), [ParagraphFormatDialog](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/paragraphformatdialog-method/llms-full.txt) | Two of the built-in dialog boxes, for character and paragraph formatting. |
| [Print](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/print-method/llms-full.txt) | Prints the document, with the print dialog or with page range, copies and collation you pass. |
| [Changed](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/changed-event/llms-full.txt), [InputPositionChanged](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/inputpositionchanged-event/llms-full.txt) | Occur when the contents change and when the input position moves. |

The [TextControl](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/llms-full.txt) reference lists all members.

### Next Steps

- [Create Your First WPF Application](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/getting-started/document-editor/first-application/llms-full.txt): put a `TextControl` into a window and run it.
- [Ribbon Tabs, Toolbars, Rulers, and Status Bar](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/overview/components/ribbon-toolbars/llms-full.txt): the controls that complete the editor.
- [XAML Integration](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/integration/xaml/llms-full.txt): declare, name and configure the controls in XAML.
- [Document Editor](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-editor/llms-full.txt): every editing feature in detail.

---

## Nearby

- **Previous:** [Components](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/overview/components/llms-full.txt)
- **Next:** [Ribbon Tabs, Toolbars, Rulers, and Status Bar](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/overview/components/ribbon-toolbars/llms-full.txt)
