SpellCheck Class (System.Windows.Controls)

Switch View :
ScriptFree
.NET Framework Class Library
SpellCheck Class

Provides real-time spell-checking functionality to text-editing controls, such as TextBox and RichTextBox.

Inheritance Hierarchy

System.Object
  System.Windows.Controls.SpellCheck

Namespace:  System.Windows.Controls
Assembly:  PresentationFramework (in PresentationFramework.dll)
Syntax

Visual Basic
Public NotInheritable Class SpellCheck
C#
public sealed class SpellCheck
Visual C++
public ref class SpellCheck sealed
F#
[<Sealed>]
type SpellCheck =  class end

The SpellCheck type exposes the following members.

Properties

  Name Description
Public property CustomDictionaries Gets the collection of lexicon file locations that are used for custom spell checking.
Public property IsEnabled Gets or sets a value that determines whether the spelling checker is enabled on this text-editing control, such as TextBox or RichTextBox.
Public property SpellingReform Gets or sets the spelling reform rules that are used by the spelling checker.
Top
Methods

  Name Description
Public method Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method Static member GetCustomDictionaries Gets the collection of lexicon file locations that are used for custom spelling checkers on a specified text-editing control.
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method Static member GetIsEnabled Returns a value that indicates whether the spelling checker is enabled on the specified text-editing control.
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method Static member SetIsEnabled Enables or disables the spelling checker on the specified text-editing control, such as TextBox or RichTextBox.
Public method Static member SetSpellingReform Determines the spelling reform rules that are used by the spelling checker.
Public method ToString Returns a string that represents the current object. (Inherited from Object.)
Top
Fields

  Name Description
Public field Static member CustomDictionariesProperty Identifies the CustomDictionaries dependency property.
Public field Static member IsEnabledProperty Identifies the IsEnabled dependency property.
Public field Static member SpellingReformProperty Identifies the SpellingReform dependency property.
Top
Remarks

To enable the spelling checker, set the SpellCheck.IsEnabled property to true on a text-editing control. When this spelling checker is enabled, misspelled words are underlined by using a red wavy line, as shown in the following illustration. Spelling checker is supported only when WPF provides a default dictionary. In .NET Framework 4, WPF provides dictionaries for English, French, German, and Spanish.

Textbox with spell-checking

To add a custom dictionary, add the location of the lexicon file to the CustomDictionaries collection.

Examples

The following example shows how to enable real-time spell checking in a TextBox by using the IsEnabled property of the SpellCheck class.

XAML

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

  <StackPanel>
    <TextBox SpellCheck.IsEnabled="True" Name="myTextBox"></TextBox>
  </StackPanel>

</Page>


Visual Basic


Imports System
Imports System.Windows
Imports System.Windows.Controls

Namespace SDKSample
	Partial Public Class SpellCheckExample
		Inherits Page
		Public Sub New()
			Dim myStackPanel As New StackPanel()

			'Create TextBox
			Dim myTextBox As New TextBox()
			myTextBox.Width = 200

			' Enable spellchecking on the TextBox.
			myTextBox.SpellCheck.IsEnabled = True

			' Alternatively, the SetIsEnabled method could be used
			' to enable or disable spell checking like this:
			' SpellCheck.SetIsEnabled(myTextBox, True)

			myStackPanel.Children.Add(myTextBox)
			Me.Content = myStackPanel
		End Sub
	End Class
End Namespace


C#

using System;
using System.Windows;
using System.Windows.Controls;

namespace SDKSample
{
    public partial class SpellCheckExample : Page
    {
        public SpellCheckExample()
        {
            StackPanel myStackPanel = new StackPanel();

            //Create TextBox
            TextBox myTextBox = new TextBox();
            myTextBox.Width = 200;

            // Enable spellchecking on the TextBox.
            myTextBox.SpellCheck.IsEnabled = true;

            // Alternatively, the SetIsEnabled method could be used
            // to enable or disable spell checking like this:
            // SpellCheck.SetIsEnabled(myTextBox, true);

            myStackPanel.Children.Add(myTextBox);
            this.Content = myStackPanel;
        }
    }
}


Version Information

.NET Framework

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Platforms

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
See Also

Reference

Other Resources

Community Content

Thomas Lee
textBox.SpellCheck Class not available in Windows Forms apps?
Does anyone know the secret of getting the .SpellCheck proprty to work in a Windows Foems (vb.net) application?


[tfl - 29 04 12] Hi - and thanks for your post. Community content is not the appropriate place for technical support queries. Instead, you should visit the MSDN Forums at http://forums.microsoft.com/MSDN, where such posts are welcomed and where you stand a much better chance of getting your query resolved. Sorry if that's not the answer you wanted to hear.


sub_j
SpellCheck Languages in .NET 3.5 and 4.0
In .NET 3.5, to have spellcheck in one of the other languages, you must download the 3.5 language pack for that language- if you are running Windows XP.  If you are running Windows Vista or Windows 7, the language packs are already included, and spellcheck in the other languages should work out of the box.

In .NET 4.0, no matter what version of Windows you are running, you will need the 4.0 language pack for the language you want to spellcheck with.  As of this moment, the 4.0 language packs are unavailable.

To enable a different langauge spellcheck, like Spanish for example, you do not set the Language or xml:lang attributes on your textbox or RichTextBox (Language maps to xml:lang).  Spellcheck occurs on the Run level of your textbox, and is based off of the user input language/keyboard language.  They can change their keyboard language mid Run, and the new Run will spellcheck in the new language.

You can force the input lanuage using InputLanguageManager.InputLanguage.  To set spellcheck for your textbox to Spanish, for example, you add the attribute InputLanguageManager.InputLanguage="es".  However, be aware that a user can change their input language/keyboard language inside the textbox, creating a new Run and spellchecking in the new language.

For .NET 3.5 lanuage packs:
http://www.microsoft.com/downloads/details.aspx?FamilyID=8489ed13-b831-4855-96f7-dd35e4c02a20&displaylang=en

For more:
http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/06a2cc61-f2ae-4534-b35a-6c676bc2bcb2/?prof=required