Skip to main content

Getting Started

  • 5 minutes to read

This document will help you learn the basics of the SpellChecker integration into your Silverlight application. It provides you with step-by-step instructions on how to create a simple application that demonstrates the spell-check functionality.

Please follow the steps below:

#Step 1. Create a Project and Add Controls

This tutorial demonstrates how to start checking the spelling in a standard TextBox control when clicking a Button, one of the wide range text-aware controls supported by the SpellChecker component. For more information, see Supported Controls.

Create a project and add the required controls.

  1. Open MS Visual Studio 2010 and create a new Silverlight Application project.
  2. Add the TextBox and Button controls (located on the Common Silverlight Controls toolbox tab) to a MainPage.
  3. Add references to the assemblies required for the DXSpellChecker suite, which are listed in the Deployment document.

    SpellChecker_AddReference

    By default, these assemblies are located in the C:\Program Files (x86)\DevExpress 14.2\Components\Bin\Silverlight.

#Step 2. Prepare a Dictionary

The next step is specifying a dictionary to perform the spell check.

In our tutorial, we'll add the Polish OpenOffice dictionary. The advantages of OpenOffice dictionaries are that they are available for free and are constantly updated, since they are a part of the open source project.

  1. On the Dictionaries page find the Polish (Poland) section, and download the Polish Dictionary Pack for OpenOffice 3.0.
  2. Rename the pack name extension to .zip and unpack it. You'll get the pl_PL.dic file, containing a list of words, and the pl_PL.aff file, containing grammar rules.
  3. Determine the standard that is used for encoding the dictionary. You can find this information in the beginning of the pl_PL.aff file. For example, the Polish OpenOffice dictionary is in ISO-8859-2 encoding (SET ISO8859-2 in the pl_PL.aff file).

    It is important to note that the Silverlight platform supports only utf-8 and utf-16 encodings. So, if an utf-8 or utf-16 standard is not used for encoding the dictionary that you want to use for spell checking, you should convert it to utf-8 encoding, and change the corresponding line in the .aff file to SET UTF-8.

    You can do this by using the CodePageConverter utility. Download it from this KB article or use the direct link and then unpack it.

  4. Copy the CodePageConverter.exe file to the folder containing the pl_PL.aff and pl_PL.dic files and run it. This will modify the pl_PL.aff and pl_PL.dic files as required, and create two files that have a _utf8 substring in their names and are ready to be used by SpellChecker (the pl_PL_utf8.aff and pl_PL_utf8.dic files).

#Step 3. Add a Dictionary

  1. Copy the pl_PL_utf8.aff and pl_PL_utf8.dic files to the folder of your project and include them in the project.

    SpellChecker_IncludeInProject

    NOTE

    If these files are not displayed in the Solution Explorer, select Show All Files from the Project menu or click Show All Files SpellChecker_ShowAllFilesIcon on the Solution Explorer toolbar.

  2. For these files, set the Build Action property to Embedded Resource.

    SpellChecker_EmbeddedResource

#Step 4. Load the Dictionary and Check Spelling

To load the Polish dictionary and start spell checking in the TextBox when an end-user clicks the button, use the following code.


using System.Windows;
using System.Windows.Controls;
using DevExpress.Xpf.SpellChecker;
using DevExpress.XtraSpellChecker;
using System.IO;
using System.Reflection;
using System.Globalization;
// ...

namespace SpellChecker_Polish {
    public partial class MainPage : UserControl {
        SpellChecker checker;
        public MainPage() {
            InitializeComponent();

            checker = new SpellChecker();

            // Obtain information about the Polish dictionary from the assembly.
            Stream dict = Assembly.GetExecutingAssembly().GetManifestResourceStream("SpellChecker_Polish.pl_PL_utf8.dic");
            Stream grammar = Assembly.GetExecutingAssembly().GetManifestResourceStream("SpellChecker_Polish.pl_PL_utf8.aff");

            // Create the dictionary and load information into it.
            SpellCheckerOpenOfficeDictionary dictionary = new SpellCheckerOpenOfficeDictionary();
            dictionary.LoadFromStream(dict, grammar, null);

            // Define the dictionary culture.
            CultureInfo culture = new CultureInfo("pl-PL");
            dictionary.Culture = culture;

            // Add the dictionary to the spell checker's collection.
            checker.Dictionaries.Add(dictionary);

            // Set the default culture of the spell checker.
            checker.Culture = culture;
        }

        private void button1_Click(object sender, RoutedEventArgs e) {
            // Start checking the text within a text box. 
            checker.Check(textBox1);
        }
    }
}