共用方式為


Custom Dictionaries

Most current editors provide built in spell checking which validates user input. Spell checkers can be found in anything from word processors, to email clients, and even web browsers. Depending on the scenario, these spell checking utilities vary in complexity. Simple spell checkers compare the input against a default dictionary and then highlight mismatches. More complex spell checkers allow dynamic modification of the dictionary.

WPF includes a spell checker, but currently it only uses the OS provided dictionary for input validation. It lacks the functionality to allow the default dictionaries to be augmented with custom dictionaries provided by an application. This has been a major issue for apps which target specific industries with specialized lingo. Those apps are plagued by misspelling notifications.

A chat client is a classic example of an application that displays specialized words. In such an application, web slang such as lol, brb, or ttyl is frequently used. While these acronyms are not official words in English, in the context of a chat client these are not misspelled words.

This problem has been fixed in WPF 4.0. The ability to augment spelling support, via an application provided custom dictionary, has been added to the framework.

 

 

 

Custom Dictionaries API

The property CustomDictionaries has been added to the SpellCheck class .

· CustomDictionaries - This is a read-only dependency property which is an IList of URIs. Each URI points to a custom dictionary to be used for spell checking. If spell checking is disabled, SpellCheck.IsEnabled == false, no spell checking will occur, even if a custom dictionary is provided.

Custom Dictionary Format

Custom dictionaries are simple text files with single words on each line. Each line represents a legitimate word which should not be marked as misspelled.

The first line of this file can specify a language that the custom dictionary should correspond to (e.g. “#LID 1033” means that this custom dictionary applies to US English). If no language is set, the custom dictionary will apply to all default dictionaries.

· #LID 1033 – English

· #LID 3082 - Spanish

· #LID 1031 - German

· #LID 1036 - French

Comments are not supported inside the custom dictionary file.

 

 

<Window x:Class="CustomSpellerDictionaries.MainWindow"

       xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation"

       xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml"

       xmlns:sys1="clr-namespace:System;assembly=system"

       Title="Custom Dictionaries Example">

    <Grid>

        <TextBox Text="Finallly, my name, Chipalo, is not marked as misspelled."

                TextOptions.TextFormattingMode="Display">

            <SpellCheck.IsEnabled>true</SpellCheck.IsEnabled>

            <SpellCheck.CustomDictionaries>

                <sys1:Uri>D:\TEMP\dictionary.lex</sys1:Uri>

            </SpellCheck.CustomDictionaries>

        </TextBox>

    </Grid>

</Window>

Contents of D:\TEMP\dictionary.lex

Chipalo

 

CustomDictionaries

TextBlock created with the above XAML. Notice that spell checking is enabled but “Chipalo” is not marked as misspelled.

Custom Dictionaries Suggested Usage

Custom dictionaries should be used when an application wants a set of words, which are not found in the default dictionary for a language, to not be marked as misspelled. Specifying a langue for a custom dictionary will limit the use of the dictionary to only the denoted language. A custom dictionary which is not marked as language specific will be used for spell checking in all languages which spell checking is supported.

Spelling support in WPF is limited to four languages: English, Spanish, French, and German. Custom dictionaries are designed to augment the default dictionaries for these languages and not to extend spelling support to other languages. Creating a custom dictionary which contains common Russian words, marking the dictionary as a Russian dictionary, and adding it to the SpellCheck object of a TextBox or RichTextbox will not add Russian spelling support. If the first line of a custom dictionary denotes that the dictionary is used for a language which is not supported, that dictionary will be ignored.

 - Chipalo

Comments

  • Anonymous
    October 26, 2009
    Still no additional dictionaries? AND the CustomDictionaries API is off limits to other languages? That's not a feature. That's the LACK of a feature as far as I'm concerned.

  • Anonymous
    November 04, 2009
    I kinda agree with Ruben. I would like to add a custom dictionary of my words, in effect, my own language. It would have been great if I could create my own language with custom dictionaries.

  • Anonymous
    November 06, 2009
    Ruben - I would agree that additional dictionaries and customization of existing dictionaries are distinct features.  Both features are targeted at specific scenarios and have different design considerations. For example, additional dictionaries (which support another language) are much larger than dictionary addons (which support industry specific lingo). The two need to be created, processed, and stored differently. We have done the work to support modification of existing dictionaries in WPF 4.0, and we would like to extend this work in future releases to support additional dictionaries. Chipalo

  • Anonymous
    November 08, 2009
    I would like very much if you have a window that can spell like I had in XP

  • Anonymous
    November 09, 2009
    Eugene - Sorry I am not sure which feature you are referring to.

  • Anonymous
    November 10, 2009
    Good to hear that custom dictionaries are in .NET 4.0.  However, where can I locate detailed information on what dictionaries are available? I understand only 4 languages are supported, English, German, French and Spanish are available.  But is only en-US supported, how about en-GB? Documentation on this topic in MSDN docs. seems sparse at best.  Where can I locate exact details on the languages supported?

  • Anonymous
    November 16, 2009
    I agree with Ruben, this is a missing feature for all people speaking other than english, french, german or spanish. "...WPF includes a spell checker, but currently it only uses the OS provided dictionary for input validation..." this is exactly what is expected from a feature like this, italian dictionary for an italian OS... I can't see any valid reason to limit this to only 4 languages, having MS full dictionaries for all localized Office version...

  • Anonymous
    November 28, 2009
    I also agree with Ruben and Nicola, that looks to me like the key feature that users want is the dictionary on its own language... custom dictionarys like you have down now is also good but not what is most wanted. Do you have that in plan for the final release of wpf4.0 ?

  • Anonymous
    December 04, 2009
    The comment has been removed

  • Anonymous
    April 07, 2010
    I wish that another languages would supported too. I have hope, is can be, example, open project for another dictionaries. But why nor create open web-service for every language with possibility add appropriate words. And then everybody developer and user would can update your's dictionary at local PC?