TX Spell .NET for WPF

TX Text Control .NET Server Document Editor

Topic

The Document Editor of TX Text Control .NET Server is a word processor in the browser, and TX Spell .NET is the spell checker behind it. Adding it takes no C# code at all: install the package TXTextControl.TXSpell.Core.SDK into the ASP.NET Core application that hosts the editor, turn spell checking on in JavaScript, and the editor underlines misspelled words and offers suggestions in its context menu, as the desktop TextControl does.

The Document Editor in a browser with the misspelled word checkking underlined and its context menu listing the suggestions checking, cheeking, chucking, chocking and checkering, followed by Ignore, Ignore All and Add to Dictionary; the status bar shows English (United States).

Before You Begin

  • TX Text Control .NET Server, a separate product with its own license. The Document Editor is part of it, not of TX Spell .NET.
  • An ASP.NET Core application with the Document Editor, built as in Document Editor in ASP.NET Core of the TX Text Control .NET Server documentation, with the packages TXTextControl.Web, TXTextControl.TextControl.Core.SDK and TXTextControl.Web.DocumentEditor.Backend.
  • TX Spell .NET for WPF installed or licensed, which gives you access to the package below.

Install the Package

The spell checker of the editor is the package TXTextControl.TXSpell.Core.SDK, version 11.0.1: the engine TXSpell.dll for .NET 8 and higher, without a user interface, with the US English dictionary, hyphenation list, thesaurus and language detection data. The package is part of TX Spell .NET for WPF: the setup adds it to the local package source Text Control Offline Packages, from which you install it like any other package. Configuring Package Sources shows how to add the source.

Install it into the project that hosts the Document Editor backend:

dotnet add package TXTextControl.TXSpell.Core.SDK

After a build, TXSpell.dll and the four language data folders are in the output folder, next to the files of the backend.

Leave Program.cs as It Is

The backend picks up TX Spell .NET from the application; nothing has to be registered, and no middleware takes a spell checker. Program.cs stays exactly as the Document Editor tutorial writes it:

using TXTextControl.Web;
using TXTextControl.Web.DocumentEditor.Backend;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddControllersWithViews();
builder.Services.AddHostedService<DocumentEditorWorkerManager>();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
    app.UseExceptionHandler("/Home/Error");
    app.UseHsts();
}

app.UseHttpsRedirection();
app.UseRouting();

app.UseWebSockets();
app.UseTXWebSocketMiddleware();

app.UseAuthorization();

app.MapStaticAssets();

app.MapControllerRoute(
    name: "default",
    pattern: "{controller=Home}/{action=Index}/{id?}")
    .WithStaticAssets();

app.Run();

Turn On Spell Checking

Spell checking in the editor is off by default: users can switch it on with Enable Spell Checking on the Proofing tab, or your code turns it on with setIsSpellCheckingEnabled. The view below loads a document, sets its language to US English with setCulture of the selection, so that the matching dictionary is used, and then switches spell checking on:

@using TXTextControl.Web.MVC

@Html.TXTextControl().TextControl().Render()

<script>
    var sDocument = "<html><body><p>Welcome to <strong>Text Control</strong></p></body></html>";

    TXTextControl.addEventListener("textControlLoaded", function () {
        TXTextControl.loadDocument(TXTextControl.StreamType.HTMLFormat, btoa(sDocument), function () {
            TXTextControl.selectAll();
            TXTextControl.selection.setCulture("en-US");
            TXTextControl.selection.setLength(0);

            TXTextControl.setIsSpellCheckingEnabled(true);
        });
    });
</script>

Spell checking uses the dictionary of the text's language. For text with a neutral language, setIsLanguageDetectionEnabled lets the editor detect the language instead.

Check That TX Spell .NET Is Found

Without the package, the Spelling & Hyphenation and Settings groups of the Proofing tab are grayed out, and no word is underlined. getIsSpellCheckingEnabled doesn't tell you, because it returns true after setIsSpellCheckingEnabled(true) even when no spell checker is present. When misspelled words stay unmarked, check that the package is in the project that hosts the backend, and see Misspelled Words Aren't Marked in the TX Text Control .NET Server documentation.

Other Languages

The package contains US English only. Dictionaries for other languages are downloads: add their files to the Dictionaries, HyphenationLists and SynonymLists folders of the project and set Copy to Output Directory for them, as Installing Dictionaries and Language Data describes. In the browser, TXTextControl.Proofing lists the dictionaries on the server, loads and removes them, and manages user dictionaries.

Everything else the editor does with spell checking, from the spell check dialog to the misspelled words in JavaScript, is described in Spell Checking of the Document Editor.

Linux and Docker

TX Spell .NET runs wherever the backend runs, on Windows, on Linux and in Linux containers. The blog article Document Editor with TX Spell .NET on Linux using ASP.NET Core builds the application with Visual Studio's container support and the default Dockerfile. Take the TX Spell package and the JavaScript from the article; for the backend, follow the current tutorial, because the article copies the backend files by hand, which the package TXTextControl.Web.DocumentEditor.Backend has since replaced. When you publish, select linux-x64 or win-x64 as the target runtime, as TX Text Control requires; the Deployment Guide of TX Text Control .NET Server covers Linux and Docker.

Each open editor session needs between 50 and 150 MB of memory on the backend, depending on the spell checking dictionaries loaded; see Architecture.

Licensing

The two products are licensed separately. TX Spell .NET is licensed per developer, and applications that use it are distributed royalty-free, including web applications and internal deployments; the license is embedded into your assembly by the package, and no license file goes to the server. TX Text Control .NET Server has its own license, with its own rules for servers. See Application Licensing.

Next Steps