TX Spell .NET for WPF

Create a .NET Framework Application

Topic

Existing WPF applications often still run on the .NET Framework, and TX Spell .NET works there as well. The result is the same editor with spell checking as in Create Your First WPF Application, reduced to the TextControl. What differs is how the components get into the project: there are no NuGet packages. TX Text Control comes from the toolbox tab its setup created, you reference the assemblies of TX Spell .NET yourself, and the license of the spell checker needs an entry in licenses.licx.

Prerequisites

  • Visual Studio on Windows with the .NET Framework 4.8.
  • The setups of TX Spell .NET for WPF 11.0 and TX Text Control .NET for WPF 34.0, the full or the trial versions. For .NET Framework projects, they provide the assemblies, the language data and the toolbox tab. See Installing the Product.

Create the Project

  1. Open Visual Studio and create a new project.

  2. Select C# from the Languages list, Windows from the Platform list and Desktop as the Project Type.

  3. Select the project template WPF App (.NET Framework) and click Next.

    The Create a new project dialog of Visual Studio with the template WPF App (.NET Framework) selected.

  4. Enter the project name Simple, select .NET Framework 4.8 in the Framework list and click Create.

Add the Editor to the Window

  1. Open MainWindow.xaml. In the XAML view, replace the Grid with a DockPanel:

    The XAML view of MainWindow with an empty DockPanel in place of the Grid.

  2. In the Toolbox, find the tab TX Text Control 34.0, which the setup of TX Text Control created, and double-click TextControl. Visual Studio adds the control inside the DockPanel and maps the prefix WPF to the namespace of TX Text Control:

    The XAML of the window with xmlns:WPF mapped to TXTextControl.WPF and a WPF:TextControl element inside the DockPanel.

  3. Remove the Height and Width attributes of the TextControl, so that it fills the window.

Reference TX Spell .NET

  1. Choose Project > Add Reference.... In the Reference Manager, click Browse.

  2. Go to the Assembly folder of the installation, by default C:\Program Files\Text Control GmbH\TX Spell 11.0 .NET for WPF\Assembly.

  3. Select TXSpell.dll and TXSpell.WPF.dll, click Add, and close the Reference Manager with OK.

    The Select the files to reference dialog of Visual Studio showing the Assembly folder of an earlier TX Spell .NET installation, with the folders de, Dictionaries, HyphenationLists, LanguageRecognition and SynonymLists and the files TXSpell.dll and TXSpell.WPF.dll selected.

TXSpell.dll holds the spell checking engine, and TXSpell.WPF.dll the WPF spell checker with its dialogs. The same Assembly folder holds the language data in the folders Dictionaries, HyphenationLists, SynonymLists and LanguageRecognition, where the spell checker finds it on the development machine.

Declare and Connect the Spell Checker

Map the namespace of TX Spell .NET to a prefix, declare the spell checker as a resource of the window, and name its key in the SpellChecker property of the TextControl. The complete MainWindow.xaml:

<Window x:Class="Simple.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:WPF="clr-namespace:TXTextControl.WPF;assembly=TXTextControl.WPF"
        xmlns:spell="clr-namespace:TXTextControl.WPF.Proofing;assembly=TXSpell.WPF"
        Title="MainWindow" Height="450" Width="800">
    <Window.Resources>
        <spell:TXSpellChecker x:Key="txSpellChecker1" />
    </Window.Resources>
    <DockPanel>
        <WPF:TextControl x:Name="textControl1"
                         SpellChecker="txSpellChecker1"
                         IsSpellCheckingEnabled="True"
                         IsHyphenationEnabled="True" />
    </DockPanel>
</Window>

The markup works as follows:

  • <spell:TXSpellChecker x:Key="txSpellChecker1" /> creates the spell checker as a resource of the window.
  • SpellChecker holds the key of the resource as plain text.
  • IsSpellCheckingEnabled underlines misspelled words, and IsHyphenationEnabled hyphenates the last word of a full line.

Add the License Entry

In a .NET Framework project, the license of the spell checker is embedded through licenses.licx when you build.

  1. Open licenses.licx in the Properties folder of the project in Solution Explorer. In Visual Basic, it is in the My Project folder.

    Solution Explorer with the project Simple, its Properties folder expanded and Licenses.licx selected.

  2. Add this line:

    TXTextControl.WPF.Proofing.TXSpellChecker, TXSpell.WPF
    

If the project has no licenses.licx yet, add a text file with this name and set its build action to Embedded Resource. Licensing covers the license problems you may meet.

Run the Application

Press F5 and type a sentence with a spelling mistake. The application behaves like the .NET application of the first tutorial: misspelled words are underlined once they are complete, English is checked out of the box, the context menu offers suggestions and opens the spell check dialog, and the last word of a full line is hyphenated.

When you deploy the application, ship the language data folders with it. See Deploying .NET Framework Applications.

The Finished Sample

The setup installs this tutorial as a finished project below TX Spell 11.0.NET for WPF\Samples\WPF in your Documents folder: CSharp\TextControl\Simple in C#, and VB.NET\TextControl\Simple in Visual Basic.

Next Steps