views:

416

answers:

2

I need to turn spellcheck on for a richtextbox, and set the language to one the user has picked from a drop down. For now, I'm just testing it by building the richtextbox in xaml and providing a language to the xaml language attribute.

I've read two different resources and one says I need to set the language attribute, and the other says I need to set the xml:lang attribute. Neither seems to work. I've tried setting either one to "es" for Spanish, and I've also tried setting both to "es". I've also tried french by setting them to "fr-FR", without success. The only thing that happens is that english words aren't marked, but the other language words are marked as misspelled.

I also read that I need to change the keyboard language. This would be a problem for my application as the language within the application needs to be switched on the fly, so having the end user go to their keyboard settings just so spellcheck will work is a problem. However, I've changed my keyboard settings, and spell check still does not work properly. This time it doesn't mark anything as misspelled, even misspelled english words.

What am I missing?

Edit: some links to my references above http://msdn.microsoft.com/en-us/library/system.windows.controls.spellcheck(v=VS.100).aspx

http://www.dev102.com/2008/03/25/customize-spellcheck-on-wpf-text-controls/

http://books.google.com/books?id=clLc5BBHqRMC&pg=PA121&lpg=PA121&dq=C%23+wpf+enable+spellcheck&source=bl&ots=_r59pZRDjP&sig=yHMBc39EHKK5gaRMzxlBaEsY890&hl=en&ei=oXnIS8zWH4G88gaq48yGBw&sa=X&oi=book_result&ct=result&resnum=6&ved=0CBMQ6AEwBQ#v=onepage&q&f=false

A: 

I'm not sure where the problem lays for you, but this definitely works on my machine:

    <StackPanel>
        <TextBox SpellCheck.IsEnabled="True"
            Language="{Binding SelectedItem.Content, ElementName=lg, ConverterCulture=en-us}">

            Turtle tortue tortuga Schildkröte 

        </TextBox>
        <ComboBox Name="lg">
            <ComboBoxItem Selector.IsSelected="True">en-US</ComboBoxItem>
            <ComboBoxItem>fr-FR</ComboBoxItem>
            <ComboBoxItem>es-ES</ComboBoxItem>
            <ComboBoxItem>de-DE</ComboBoxItem>
        </ComboBox>
    </StackPanel>

Edit works in 3.5, not in 4.0. Interesting.

In 3.5 all supported dictionaries work fine. In 4.0 WPF spell check works only for English language.

Edit 2

It's seems that it works only on 3.5 because I'm on Windows 7, so I don't need language packs.

The other problem is that it works only because the text is preset. Any text you enter will get it's language from current user settings.

I guess the solution to your problem would be to traverse the entire content and change it's Language properties each time the user selects a language.

majocha
mojocha, do you have the language packs installed? I posted this same question in the MSDN forum, and the moderator told me I need to download the language packs for 3.5. After doing that and about an hour of testing, the language packs get spellcheck working only for 3.5. So spellcheck still does not work for me in 4.0 in other languages, but will for Spanish in 3.5 because I now have that language pack. It also only works in a given language provided the keyboard is set to that language. So when you start typing, if your keyboard is set to Spanish, it will spellcheck in Spanish.
sub-jp
If your keyboard is set to English, it will spellcheck in English. So it appears to check the language on the <Run> level. Any default text is checked in the inherited language. So if I set my RichTextBox to language="es", and input some hardcoded text, it gets spellchecked in Spanish not only at runtime, but in the designer window.
sub-jp
link:http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/06a2cc61-f2ae-4534-b35a-6c676bc2bcb2/?prof=required
sub-jp
I've edited my answer.
majocha
Yup, that would make sense according to the MSDN forum, if you're running Windows 7, the language packs are included already.
sub-jp
+1  A: 

From the MSDN forum:

"First, we exactly components do we need for WPF to enable spell check for English/Spanish/German/French languages?

NetFx 3.5 SP1

Windows XP (Language Packs); Windows Vista (Out of box); Windows 7 (Out of box)

NetFx 4 Windows XP (Language Packs); Windows Vista (Language Packs); Windows 7 (Language Packs)

Here 'Language Packs' means you need to install corresponding .NET Framework Language Packs. For example, if you want to enable Spanish spell check on Windows XP and .NET Framework 3.5 SP1, then you install the .NET Framework 3.5 SP1 Spanish Language Pack. And if you want to enable German spell check on .NET Framework 4.0, then you install the .NET Framework 4.0 German Language Pack.

The Language Packs for .NET Framework 4.0 will be available soon.

Out of box means you don't have to do anything and the spell check for the four languages are automatically available.

If you're deploying your application via ClickOnce, you can include the corresponding language packs as prerequisites. For help on including language packs in a ClickOnce deployment, you can use the ClickOnce and Setup & Deployment Projects Forum.

Second, how does RichTextBox control determine the language to check?

If a Run element is marked with specific language, spell check will use it:

uno dos tres cuatrro one two three fourr

At runtime, the spell check uses the input language that was used to type in the words, as described in previous post.

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

sub-jp
So, simply you have to wait for 4.0 Language Packs
majocha
lol yup... unless your app is in 3.5. Ours is currently in 3.5 but we were looking to bump it up to 4.0 as soon as possible. Probably still happen, multilingual spellcheck isn't as high on the priority list.
sub-jp