RichTextBox for UWP | ComponentOne
Working with RichTextBox for UWP / Main Concepts and Features / Spell Checking / Adding Spell Checking
In This Topic
    Adding Spell Checking
    In This Topic

    In this topic you'll add spell-checking to your application. This topic assumes you have added a C1RichTextBox control and a C1RichTextBoxMenu control to your page.

    In this help topic, you'll use an English dictionary resource. If you wish to use a different dictionary, you may choose any from the 22 supported dictionaries.

    The main steps for adding spell-checking are to declare a new C1SpellChecker, load the Main Dictionary of your choice, and to assign C1SpellChecker to the SpellChecker property of your C1RichTextBox.

    1. Edit the C1RichTextBox and C1RichTextBoxMenu controls to reflect the following:
      XAML Markup
      Copy Code
      <c1RTB:C1RichTextBoxMenu x:Name="rtbMenu" RichTextBox="{Binding ElementName=rtb}"/>
         <c1RTB:C1RichTextBox x:Name="rtb"  BorderThickness="2" BorderBrush="DarkGray" />
      

    2. In the Solution Explorer, right-click your application's name and select Add | New Folder. Name the folder Resources.
    3. In the Solution Explorer, right-click the Resources folder and select Add | Existing Item. The Add Existing Item dialog box will appear.
    4. In the Add Existing Item dialog box locate the C1Spell_en-US.dct file included in the RichTextBoxSamples sample folder.
      This is a US English dictionary file – if you add another file, instead, you can adapt the steps below with the appropriate code.
    5. In the Properties window, set the C1Spell_en-US.dct file's Build Action to Embedded Resource.
    6. Right-click your MainPage.xaml page and select View Code from the context menu.
    7. Add the following import statements to the top of the page:
      C#
      Copy Code
       using C1.Xaml.SpellChecker;
       using C1.Xaml.RichTextBox;
      

    8. Set the Text property in the MainPage() constructor:
      C#
      Copy Code
      rtb.Text = @"Some facts about Mark Twain (spelling errors intentional ;-) A steambat pilot neded a vast knowldege of the ever-chaging river to be able to stop at any of the hundreds of ports and wood-lots along the river banks. Twain meticulosly studied 2,000 miles (3,200 km) of the Mississipi for more than two years before he received his steamboat pilot license in 1859.";
      

    9.  Declare a new C1SpellChecker:
      C#
      Copy Code
      var spell = new C1SpellChecker();
      

    10. Assign C1SpellChecker to the SpellChecker property of your C1RichTextBox control:
      C#
      Copy Code
       rtb.SpellChecker = spell;
      

    11. Obtain the stream to your resource file. Make sure you insert your application name where indicated:
      C#
      Copy Code
      Assembly asm = typeof(MainPage).GetTypeInfo().Assembly;
      Stream stream = asm.GetManifestResourceStream("YourApplicationName.Resources.C1Spell_en-US.dct");
      

    12. Load the MainDictionary of your choice:
      C#
      Copy Code
      spell.MainDictionary.Load(stream);
      


    What You've Accomplished

    In this topic, you added text to your C1RichTextBox control, and then added some code to handle spell-checking.