# Architecture and Control Lifecycle

> The WPF TextControl in a window: bars connected by name, text parts and the input focus, startup code in Loaded, FormattingPrinter and ServerTextControl.

- **Product:** TX Text Control .NET for WPF
- **Section:** Documentation
- **Kind:** Topic
- **Path:** TX Text Control .NET for WPF > Document Editor > Architecture and Control Lifecycle
- **1405 words**
- **Web URL:** https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-editor/architecture/
- **LLMs URL:** https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-editor/architecture/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-editor/architecture/llms-full.txt

---

In a WPF window, the `TextControl` exists as soon as `InitializeComponent` has run, but it can't work with a document until WPF has loaded it into the window. That gap, the text parts a document consists of, and the way the control is wired to its toolbars through XAML shape how you write an editor application. What follows explains each of them, so that your startup code, your formatting code and your save logic run at the right time and on the right part of the document.

[Product Architecture](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/overview/architecture/llms-full.txt) gives the overview of the product, and [WPF.TextControl](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/overview/components/textcontrol/llms-full.txt) introduces the control.

### What the 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 derived from `System.Windows.Controls.Control`. Its template shows the document in a `ScrollViewer`, as [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, and [TextControlDocument](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/integration/data-binding/textcontroldocument/llms-full.txt) in the Integration Guide shows how to use the canvas that represents the document.

The toolbars, rulers, status bar and ribbon tabs are separate WPF controls, and the `TextControl` refers to them by name: properties such as [ButtonBar](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/buttonbar-property/llms-full.txt), [RulerBar](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/rulerbar-property/llms-full.txt) and [RibbonFormattingTab](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/ribbonformattingtab-property/llms-full.txt) are strings that contain the `x:Name` of the connected control. [Connection by Name](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-editor/ribbon-ui/ribbon-xaml/#connection-by-name) lists all of these properties, and [Connect Rulers, Toolbars, and a Status Bar](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/getting-started/document-editor/rulers-toolbars/llms-full.txt) shows the connections step by step.

### How a Document Is Organized

A TX Text Control document consists of several *text parts*: the main text, the text frames, the headers and footers, and the footnote sections. Each text part has its own paragraphs, lines, tables, images and fields, and all of them implement [IFormattedText](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/iformattedtext/llms-full.txt), as do the WPF `TextControl` and [ServerTextControl](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/servertextcontrol/llms-full.txt). Code that formats text or fills a table therefore works the same way on a text frame, on a header and on the document of a `ServerTextControl`.

For an editor, one rule matters most: [Selection](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/selection-property/llms-full.txt), [Paragraphs](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/paragraphs-property/llms-full.txt), `Tables` and most other collections of the `TextControl` refer to the text part with the input focus. While the user edits a footer, a button that makes the selection bold formats text in the footer. [Document Object Model](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/object-model/llms-full.txt) shows the tree of text parts and collections, lists which properties follow the input focus and which cover the whole document, and moves the input focus back to the main text with `TextParts.Activate`.

[Headers and Footers](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-editor/headers-footers/llms-full.txt), [Text Frames and Shapes](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-editor/text-frames-shapes/llms-full.txt) and [Footnotes](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-editor/footnotes/llms-full.txt) cover each kind of text part.

### The Life of the Control

The window creates and releases the `TextControl`; it needs no call to `Create`. Connect event handlers in the constructor of the window, after `InitializeComponent`, and work with the document, such as loading the first file or setting the focus, from the `Loaded` event of the control. [The Lifecycle of the Control](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/integration/initialization/#the-lifecycle-of-the-control) lists every stage and the events that mark it, from the constructor to the `Closing` event of the window, and [Members That Exist Only at Run Time](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/integration/initialization/#members-that-exist-only-at-run-time) names the members that don't work before `Loaded`.

[Track Unsaved Changes](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-editor/events/#track-unsaved-changes) combines the events into a flag for unsaved changes, and [Control Initialization](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/troubleshooting/initialization/llms-full.txt) in Troubleshooting helps when startup code has no effect.

### Formatting With a Printer

The layout of a document depends on the device whose text dimensions format it. [FormattingPrinter](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol-wpf/textcontrol/formattingprinter-property/llms-full.txt) names that printer, `Standard` or `Display`, as [Print Exactly What the Screen Shows](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-editor/printing/#print-exactly-what-the-screen-shows) explains. Set it in XAML, for example `FormattingPrinter="Display"`, or in code. Because TX Text Control asks the printer for information while it initializes, a printer that responds slowly delays the start of the control; [The Editor Starts Slowly](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/troubleshooting/printing/#the-editor-starts-slowly) in Troubleshooting has the fix.

### Several Editors and Background Work

Every `TextControl` in a window keeps a document of its own. To show the same content in two editors, save it from one, for example to a byte array, and load it into the other.

Document work that doesn't need the user, such as creating many documents or preparing one before it is shown, runs in a [ServerTextControl](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/servertextcontrol/llms-full.txt), which has the same programming interface and no user interface. Unlike the WPF `TextControl`, it is created in code, initialized with [Create](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/servertextcontrol/create-method/llms-full.txt) before any other member is used, and disposed of afterward. [Using ServerTextControl in Desktop Applications](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/servertextcontrol/llms-full.txt), [Dispatcher and UI Thread Access](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/performance/dispatcher/llms-full.txt) and [Background Operations](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/performance/background-operations/llms-full.txt) go further.

### Next Steps

- [Loading and Saving Documents](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-editor/load-save/llms-full.txt): every way to get a document into the editor and out again.
- [Selections and Caret Position](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-editor/editing-text/selections/llms-full.txt): the selection and the input position in code.
- [Events](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-editor/events/llms-full.txt): the events of the `TextControl`.
- [Add TextControl in XAML](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/getting-started/document-editor/xaml/llms-full.txt): the XAML of a first editor window.

---

## Nearby

- **Previous:** [Document Editor](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-editor/llms-full.txt)
- **Next:** [Loading and Saving Documents](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-editor/load-save/llms-full.txt)
