TX Text Control .NET for WPF

Architecture and Control Lifecycle

Topic

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 gives the overview of the product, and WPF.TextControl introduces the control.

What the WPF TextControl Is

TextControl 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 describes, and TextControlDocument 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, RulerBar and RibbonFormattingTab are strings that contain the x:Name of the connected control. Connection by Name lists all of these properties, and Connect Rulers, Toolbars, and a Status Bar 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, as do the WPF TextControl and ServerTextControl. 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, Paragraphs, 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 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, Text Frames and Shapes and Footnotes 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 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 names the members that don't work before Loaded.

Track Unsaved Changes combines the events into a flag for unsaved changes, and Control Initialization 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 names that printer, Standard or Display, as 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 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, which has the same programming interface and no user interface. Unlike the WPF TextControl, it is created in code, initialized with Create before any other member is used, and disposed of afterward. Using ServerTextControl in Desktop Applications, Dispatcher and UI Thread Access and Background Operations go further.

Next Steps