Krythic
Krythic

Reputation: 4364

How does WPF Spellchecking Work Internally?

As I was developing the interface for my current project, I came to the realization the WPF has built-in spellchecking available for TextBoxes, etc. I don't know why this surprised me, but it did. Perhaps because I'm quite used to Winforms, which did not include spellchecker functionality.

enter image description here

I was completely unaware of this, and more importantly, a little stunned that I never even noticed such a feature being loaded at runtime. You would think that loading the word list would incur some sort of startup-time limitation, given that the built-in dictionary is apparently pretty good; I tried to test it's capabilities and it offered words that I didn't even think would be within a standard dictionary.

So essentially, I'm really just wondering how such a feature is initialized at runtime. How does WPF handle loading the words? Does it defer the loading off to, say, the windows environment when the computer is started up? Does it load the dictionary every time the application is started? Is said dictionary located at some sort of accessible level on disk so that I can take a look at it?

Upvotes: 4

Views: 254

Answers (1)

Hans Passant
Hans Passant

Reputation: 941317

WPF uses COM interop to take advantage of spell support built into Windows. It does depend on what version you have. For Windows 8 and up it uses documented api. The spell checker is done by ISpellCheckerFactory and friends, implemented by c:\windows\system32\MsSpellCheckingFacility.dll. And it calls in the help of a WinRT class to break up a sentence into words, Windows.Data.Text.WordSegmenter gets that job done.

Neither of those components are available on Win7 and less, it then falls back to a COM service implemented by c:\windows\system32\NaturalLanguage6.dll, ILexicon is the main interface. That one is not documented by Microsoft, but visible in the reference source.

Upvotes: 8

Related Questions