Friday, May 16, 2014

Using WCF to enable spellcheck on a textbox in 3 steps

This post will show you how to enable spell check on a textbox within a form using built-in WCF controls.

1. Right Click on form design node within the AOT and add the control "ManagedHosts"
2. Select PresentationFramework and then the Textbox control.
3. On the forms init method type the following

public void init()
{
         System.Windows.Controls.TextBox textBox         

          super();

          textBox = TextBoxManagedHost.control();
          Systsem.Windows.Controls.SpellCheck::SetIsEnabled(textBox, true);

}



SpellCheck will now be enabled on the text box control you added and after hitting the space bar if a word is misspelled you will see a red underline and the ability to right click on the word and see a suggested spelling.

Note: because this is a managed host control you can not tie it to a datasource and will need to write code to pass in the value and save it.

2 comments:

  1. Hi Adam,

    How can we use this with existing field or you can say datasource field??
    Please suggest

    ReplyDelete
  2. You would need to write code on the forms run method to load it and on close to save it since it's technically a .net control so you can't tie it to a datasource via properties

    ReplyDelete