Product Architecture
Knowing how the parts of TX Spell .NET for WPF fit together makes it easier to add it to a project and to deploy the result. The sections below describe the assemblies and classes, the language data they read, how TX Text Control and other controls use the spell checker, and what each NuGet package brings.
How the Parts Fit
WPF application
┌──────────────────────────────────────────────────────────────────┐
│ TextControl ── SpellChecker ──►┐ (key of a XAML resource) │
│ RichTextBox / TextBox ─ Check ─► TXSpellChecker │
│ (dialogs, menu items, events) │
│ TXSpell.WPF.dll │
│ │ │
│ Console, service, server ─────────► TXSpell │
│ (checking, suggestions, │
│ hyphenation, synonyms, │
│ language detection) │
│ TXSpell.dll │
└─────────────────────────────────────────┬────────────────────────┘
│ reads
Dictionaries HyphenationLists SynonymLists LanguageRecognition
TX Spell .NET has one engine, TXSpell.dll, shared by all its products, and one assembly with the user interface for each platform, here TXSpell.WPF.dll. Both read the language data from four folders next to the application.
The Two Classes
The spell checker you declare in XAML is TXSpellChecker, in the namespace TXTextControl.WPF.Proofing of TXSpell.WPF.dll. It brings the dialogs, the context menu items and the events, and it initializes itself when it is connected to a TextControl. TXSpell, in the namespace TXTextControl.Proofing of TXSpell.dll, is the engine for code, with no user interface and no events; TXSpell compares the two in a table.
Both classes check text, create suggestions, hyphenate, find synonyms and detect languages with the same members, such as Check, CreateSuggestions and GetHyphenationPoints. The classes of the language data, such as OpenOfficeDictionary, UserDictionary and HyphenationList, are shared by both and are in the namespace TXTextControl.Proofing, which WPF code uses together with TXTextControl.WPF.Proofing. Components describes each part.
The texts of the dialogs are resources: English is built in, German comes as the satellite assembly de\TXSpell.resources.dll, and Localization and Resource Kit adds other languages.
The Language Data
The spell checker reads its language data from four folders: Dictionaries for spell checking and suggestions, HyphenationLists for hyphenation, SynonymLists for synonyms and LanguageRecognition for language detection. By default, it finds them next to the application, and on the development machine below the \Assembly folder of the installation; a property per folder, such as DictionariesDirectoryPath, moves them elsewhere. Installing Dictionaries and Language Data lists the files of each folder and where the spell checker looks.
How TX Text Control Uses the Spell Checker
A TextControl gets its spell checker through its SpellChecker property, which holds the key of the spell checker in the resources of the window. From then on, the editor drives the checking, and the spell checker answers:
- The user types a word. When the word is complete, the
TextControlasks the spell checker whether it is spelled correctly. - The
TextControlunderlines the misspelled words and keeps them in its MisspelledWords collection, which holds the misspelled words of the part of the document with the input focus, such as the main text, a header or a text frame. - A right-click on an underlined word opens the spell check menu; the menu and the dialogs correct the word in the document.
IsSpellCheckingEnabled, IsHyphenationEnabled and IsLanguageDetectionEnabled of the TextControl switch the three services on. As-You-Type Checking describes the connection in detail.
How Other Controls Use It
A RichTextBox or a TextBox doesn't know the spell checker. Your application does the work the TextControl does by itself:
- It passes the text to Check, which fills IncorrectWords with the misspelled words and their positions.
- It marks the words, or opens the spell check dialog for them.
- It applies each correction the user makes in the IncorrectWordChanging event.
Checking on Demand shows these steps with a TextBox.
The NuGet Packages
TXTextControl.TXSpell.WPF.SDK contains both assemblies, and TXTextControl.TXSpell.Core.SDK contains TXSpell.dll only, for code without a user interface. Both bring the US English language data and the license file, and neither depends on TX Text Control: a project with a TextControl installs the TX Text Control package as well. Package Overview lists what each package contains.
One Spell Checker for Many Controls
One TXSpellChecker serves every TextControl and every other control of a window. The dictionaries are loaded once, and a word the user adds to a user dictionary is accepted in all editors at once. Checking Multiple Controls shows how to share it and how one dialog checks several controls.
Next Steps
- Components: what each part does.
- Supported Platforms: the .NET versions and tools.
- Loading and Managing Dictionaries: the dictionaries in code.
- Getting Started: a first application.