WPF richtextbox 上的多语言拼写检查

发布于 2024-08-28 19:29:57 字数 1549 浏览 2 评论 0原文

我需要为富文本框打开拼写检查,并将语言设置为用户从下拉列表中选择的语言。目前,我只是通过在 xaml 中构建 richtextbox 并向 xaml 语言属性提供语言来测试它。

我读过两种不同的资源,一种说我需要设置语言属性,另一种说我需要设置 xml:lang 属性。似乎两者都不起作用。我尝试过将西班牙语的其中一个设置为“es”,并且还尝试将两者都设置为“es”。我也尝试过将法语设置为“fr-FR”,但没有成功。唯一发生的事情是英语单词没有被标记,但其他语言单词被标记为拼写错误。

我还了解到我需要更改键盘语言。这对我的应用程序来说将是一个问题,因为应用程序中的语言需要动态切换,因此让最终用户进入键盘设置以便拼写检查正常工作是一个问题。但是,我更改了键盘设置,拼写检查仍然无法正常工作。这次它不会将任何内容标记为拼写错误,甚至是拼写错误的英语单词。

我缺少什么?

编辑: 上面我的参考文献的一些链接 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=结果&resnum=6&ved=0CBMQ6AEwBQ#v=onepage&q&f=false

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夏有森光若流苏 2024-09-04 19:29:57

我不确定你的问题出在哪里,但这绝对适用于我的机器:

    <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>

编辑适用于 3.5,而不适用于 4.0。有趣的。

在 3.5 中,所有受支持的字典都可以正常工作。在 4.0 WPF 中,拼写检查仅适用于英语。

编辑2

似乎它只适用于3.5,因为我使用的是Windows 7,所以我不需要语言包。

另一个问题是它只能在文本被预设的情况下起作用。
您输入的任何文本都将从当前用户设置中获取其语言。

我想解决您的问题的方法是遍历整个内容并在每次用户选择语言时更改其语言属性。

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.

葬﹪忆之殇 2024-09-04 19:29:57

来自 MSDN 论坛:

“首先,我们确实需要 WPF 组件来启用英语/西班牙语/德语/法语的拼写检查吗?

NetFx 3.5 SP1

Windows XP (语言包);Windows Vista(开箱即用)Windows 7(开箱即用)

NetFx 4
Windows XP(语言包); Windows Vista(语言包); Windows 7(语言包)

这里的“语言包”是指您需要安装相应的.NET Framework语言包。例如,如果要在 Windows XP 和 .NET Framework 3.5 SP1 上启用西班牙语拼写检查,则需要安装 .NET Framework 3.5 SP1 西班牙语语言包。如果要在 .NET Framework 4.0 上启用德语拼写检查,则需要安装 .NET Framework 4.0 德语语言包。

.NET Framework 4.0 的语言包即将推出。

开箱即用意味着您无需执行任何操作,四种语言的拼写检查就会自动可用。

如果您通过 ClickOnce 部署应用程序,则可以包含相应的语言包作为先决条件。有关在 ClickOnce 部署中包含语言包的帮助,您可以使用 ClickOnce 和安装和安装部署项目论坛。

二、RichTextBox控件如何确定要检查的语言?

如果 Run 元素标有特定语言,拼写检查将使用它:

乌诺·多斯·特雷斯·夸特罗

一二三四

在运行时,拼写检查使用用于键入单词的输入语言,如上一篇文章中所述。

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文