Compartir a través de


Spell checking in Windows Presentation Foundation

One of the features that impressed PDC attendees was the built-in spell checker in Windows Presentation Foundation. Activating it is just as simple as setting the IsSpellCheckEnabled property to true on a TextBox or RichTextBox control.

<DockPanel xmlns=" https://schemas.microsoft.com/winfx/avalon/2005 ">
<TextBox IsSpellCheckEnabled='True'>This text is wronw.</TextBox>
<RichTextBox IsSpellCheckEnabled='True'>
<FlowDocument><Paragraph>This text is also wronw.</Paragraph></FlowDocument>
</RichTextBox>
</DockPanel>

Users will get red 'squigglies' under the misspelled words, and the context menu will come up with suggestions. Was that easy or what?

This posting is provided "AS IS" with no warranties, and confers no rights.

Comments

  • Anonymous
    September 21, 2005
    Wow. This is great. :)
  • Anonymous
    September 21, 2005
    It's working for non English languages also. Hmm, good. Mine is Hungarian. This one is installed by the Office 2003 MUI on my computer.
  • Anonymous
    September 21, 2005
    Does this work using the Word/Outlook spellcheck engine or just has a built-in one? I can't test it as I have office installed (and Sept CTP, Vista PDC build).

    If it has its own spellcheck engine, this is AWESOME!!! Now only if we can extend this (and add things like "Add to Dictionary" or other stuff)

    Thanks for showing this example!

    - Keeron
  • Anonymous
    September 22, 2005
    Kazi - weeird. I don't think the speller engine should be picking up any dictionary that is not installed with WPF - if it does, I believe it's an error.

    Keeron - yes, the WPF speller has its own engine, and should be independent of others that may be on the user's system. See my confuzed reply above. We are considering what level of extensibility we will give to the spell checking feature, but it will in all likelihood not be very comprehensive, I'm sorry to say. Like the undo/redo sytem in the editing controls, this is meant as a transient, in-memory thing (note that you have an Ignore menu item).
  • Anonymous
    September 23, 2005
    Sorry everybody, it seems it doesn't really work well on my computer. I have checked it again, but the result is a bit confusing. If I change the xaml, it underlines the whole text, but if I change the text whithin the textboxes, the spellchecker accepts anything and hides the red wavy lines. That's why I thought that it's working with non english languages.
  • Anonymous
    September 24, 2005
    It's work completely weird on my computer. The spellchecker never accepts english words only sentences, but accepts hungarian sentences again. But here is an extreme example:

    "This is a Hungarian sentence." The spellchecker does not accept it, the whole sentence is underlined.

    But if I insert one valid hungarian word for the first place:
    "Ez This is a Hungarian sentence."
    It accepts as a valid sentence, the wavy red underline disappears.

    But if I insert a not valid hungarian word:
    "Ezz This is a Hungarian sentence." the red unerline appears again.

    I use english version of XP with hungarian locale settings. Is that may be the source of the problem?
  • Anonymous
    September 27, 2005
    Kazi: yep, your description sounds weird all right :-) I'll forward this to our local spell checker experts and have them take a look