拼写检查仅替换 TextBox 中的第一个单词 [英] Spellcheck only replaces first word in TextBox

查看:22
本文介绍了拼写检查仅替换 TextBox 中的第一个单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我以前在某个地方见过这个问题,但我不确定当时是否有答案.我正在尝试将 SpellCheck 添加到 WPF、.NET 4.0 中的 TextBox.它在查找和标记不正确的单词方面工作正常,如果不正确,将替换 TextBox 中的第一个单词.任何超过一个词的东西,它只是将克拉移动到 TextBox 的开头而不改变任何东西?正如我所说,我在大约 6-9 个月前的某个地方看到过这个,但现在我在谷歌中提出的所有内容都与替代语言有关(我现在严格使用英语).我包含事件方法和 XAML 样式只是为了完整性,我认为问题不在这里.

I know I have seen this problem before somewhere, but I'm not sure if there was an answer at the time. I'm trying to add SpellCheck to a TextBox in WPF, .NET 4.0. It works fine in terms of finding and marking the incorrect words, and will replace the first word in the TextBox if it's incorrect. Anything past word one though, and it just moves the carat to the start of the TextBox without changing anything? As I said I saw this somewhere about 6-9 months ago, but now everything I come up with in google deals with alternate languages (I'm staying strictly in English for now). I've included the event methods and styling XAML only for completeness, I don't think the issue lies there.

XAML:

<MultiBox:MultiBox Name="callNotes" Grid.Column="1" Width="Auto" Height="Auto" Margin="2,5,15,20" VerticalAlignment="Stretch" AcceptsReturn="True" FontWeight="Bold" GotFocus="callNotes_GotFocus" SelectAllOnGotFocus="False" SpellCheck.IsEnabled="True" xml:lang="en-US" Style="{StaticResource TextBoxStyle}" TextChanged="callNotes_TextChanged" TextWrapping="Wrap" VerticalScrollBarVisibility="Auto" />

<Style x:Key="TextBoxStyle" TargetType="{x:Type MyNamespace:MultiBox}">
    <Setter Property="CharacterCasing" Value="Upper" />
    <Setter Property="HorizontalAlignment" Value="Stretch" />
    <Setter Property="VerticalAlignment" Value="Top" />
    <Setter Property="Height" Value="23" />
    <Setter Property="Width" Value="Auto" />
    <Setter Property="SelectAllOnGotFocus" Value="True" />
    <Setter Property="TextWrapping" Value="Wrap" />
</Style>

代码:

private void callNotes_TextChanged(object sender, TextChangedEventArgs e)
{
    callNotes.Text.ToUpper();
    lineCountOne.Content = ((callNotes.Text.Length / 78) + 1);
}

private void callNotes_GotFocus(object sender, RoutedEventArgs e)
{
    callNotes.CaretIndex = callNotes.Text.Length;
}

推荐答案

查看尝试更正错误的代码会有所帮助.这是一个简单的代码,它遍历所有检测到的错误并接受第一个建议.如果您只想修复特定错误,则需要通过获取特定索引处的错误来跳至您感兴趣的特定错误.

It would help to see your code which attempts to correct the errors. Here's simple code which loops through all the detected errors and accepts the first suggestion. If you only want to fix particular errors, you'll need to skip to the particular error you're interested in by getting the error at a certain index.

        int ndx;
        while ((ndx = callNotes.GetNextSpellingErrorCharacterIndex(0, LogicalDirection.Forward)) != -1) 
        {
            var err = callNotes.GetSpellingError(ndx);
            foreach (String sugg in err.Suggestions)
            {
                err.Correct(sugg);
                break;
            }
        }

这篇关于拼写检查仅替换 TextBox 中的第一个单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆