TX Spell .NET for WPF

TXSpell

Topic

Not every text that needs checking is in a window. A service that validates form input, a batch job that checks documents before they are published, or the server behind the Document Editor of TX Text Control .NET Server needs spell checking without dialogs or menus. TXSpell is the class for that: the spell checking engine of TX Spell .NET without a user interface.

What TXSpell Is

The class is TXTextControl.Proofing.TXSpell. It checks text, creates suggestions, hyphenates words, looks up synonyms and detects languages, with the same language data as the TXSpellChecker component. It has no dialogs, no context menu items and no events: your code calls a method and reads the result.

Unlike TXSpellChecker, it must always be initialized with Create, and it connects to TX Text Control only through the ServerTextControl of TX Text Control .NET Server, not to the TextControl of WPF. Product Architecture compares the two classes.

Use TXSpellChecker when a WPF control shows the text; the class description in the reference recommends it for text components. Use TXSpell everywhere else.

Where It Runs

TXSpell is in TXSpell.dll, the assembly that all TX Spell .NET packages share. The package TXTextControl.TXSpell.Core.SDK contains only this assembly, its German resources, the license file and the US English language data. It targets .NET 8 and doesn't depend on TX Text Control or any other package, so it runs in:

  • console applications, services and ASP.NET Core applications;
  • on Windows and on Linux, for example in a Docker container;
  • together with the ServerTextControl and the Document Editor of TX Text Control .NET Server.

The setup of TX Spell .NET for WPF provides the package through the package source Text Control Offline Packages. Without TX Text Control, an application that uses it is published without a target runtime. The blog article Document Editor with TX Spell .NET on Linux using ASP.NET Core runs it in a Linux container.

How You Work With It

  1. Create an instance and call Create. It loads the language data; before it, every check throws an exception that asks for it.
  2. Call a method: Check, CreateSuggestions, GetHyphenationPoints, CreateSynonyms or DetectLanguageScopes.
  3. Read the result from the matching property, such as IncorrectWords or Suggestions.

TXSpell doesn't implement IDisposable, so it needs no using statement. With TX Text Control .NET Server, assign the instance to the SpellChecker property of a ServerTextControl, which then finds the misspelled words and hyphenates documents in code.

Checking Text in Code builds a console application with TXSpell step by step, from creating the project to running it.

Key Members

MemberPurpose
CreateLoads the language data; call it first
Check, IncorrectWordsCheck a text, and the words found
CreateSuggestions, SuggestionsSuggestions for a word
IgnoreWord, IgnoreCaseWhich words are skipped
Dictionaries, LanguageThe dictionaries, and the default one
GetHyphenationPoints, HyphenationListsHyphenation points of a word
CreateSynonyms, SynonymListsSynonyms of a word
DetectLanguageScopes, LanguageScopesThe languages of a text
DictionariesDirectoryPathThe folder of the dictionaries, and like it the folders of the other language data

The TXSpell reference lists all members.

Next Steps