C# WPF Richtextbox中的自动更正

C# WPF Richtextbox中的自动更正,c#,.net,wpf,.net-4.6.1,C#,.net,Wpf,.net 4.6.1,我在网上看到.NET4.6.1现在支持自动更正。 %appdata%/Microsoft/Spelling//中的文件是自动创建的,我在default.acl中添加了以下行(文件仍然是带BOM的UTF-16): 我已将项目设置为目标4.6.1,并在RichTextBox上启用拼写检查: <RichTextBox SpellCheck.IsEnabled="True" Language="de-DE"/> 虽然它以通常的方式在键入错误时突出显示单词,但不会发生自动更正 我错过了什

我在网上看到.NET4.6.1现在支持自动更正。 %appdata%/Microsoft/Spelling//中的文件是自动创建的,我在default.acl中添加了以下行(文件仍然是带BOM的UTF-16):

我已将项目设置为目标4.6.1,并在RichTextBox上启用拼写检查:

<RichTextBox SpellCheck.IsEnabled="True" Language="de-DE"/>

虽然它以通常的方式在键入错误时突出显示单词,但不会发生自动更正

我错过了什么? 我不太理解这张纸条:

注意:WPF拼写检查API不直接支持这些新文件格式,应用程序中提供给WPF的自定义词典应继续使用.lex文件


我知道这是旧的,但据我所知,你需要自己处理自动更正(如果我错了,请用一个例子纠正我)。您可以按如下方式执行此操作:

var caretPosition = richTextBox.CaretPosition;
// Make sure you're passing a textpointer at the end of the word you want to correct, i.e. not like this ;)
errorPosition = richTextBox.GetNextSpellingErrorPosition(caretPosition, LogicalDirection.Backward);
if(errorPosition == null)
{
    return;
}

var errors = richTextBox.GetSpellingError(errorPosition);
// Default would be to only replace the text if there is one available replacement
// but you can also measure which one is most likely with a simple string comparison
// algorithm, e.g. Levenshtein distance
if (errors.Suggestions.Count() == 1) 
{
    var incorrectTextRange = richTextBox.GetSpellingErrorRange(errorPosition);
    var correctText = error.Suggestions.First();
    var incorrectText = incorrectTextRange.Text;

    // Correct the text with the chosen word...
    errors.Correct(correctText);
}

// Set caret position...

一个重要的注意事项不是使用RTB的CaretPosition,而是在您希望更正的单词的末尾使用textpointer。如果您的文本指针/插入符号位于一个奇怪的位置(例如,20个空格的结尾),GetNextSpillingErrorPosition方法可能需要60秒才能返回(取决于RTB中的硬件/字数)。

当我将“trambampolin”添加到default.dic文件时,Richtextbox不再将该单词标记为拼写错误。右键单击时“trambampolin”我还从.acl文件中获得了建议替换的字符串。但我希望在点击时自动替换它(如自动更正通常有效)空格。MSDN文章中对.acl文件的引用是为了完整地描述%appdata%下的ISpellChecker字典注册。我认为此引用有点误导性-WPF没有引入自动更正。相反,WPF使用此基础字典注册机制,直到字典与它的功能相关,即错误检测和提供建议。MSDN文章可能需要清楚地阐明这一点。
var caretPosition = richTextBox.CaretPosition;
// Make sure you're passing a textpointer at the end of the word you want to correct, i.e. not like this ;)
errorPosition = richTextBox.GetNextSpellingErrorPosition(caretPosition, LogicalDirection.Backward);
if(errorPosition == null)
{
    return;
}

var errors = richTextBox.GetSpellingError(errorPosition);
// Default would be to only replace the text if there is one available replacement
// but you can also measure which one is most likely with a simple string comparison
// algorithm, e.g. Levenshtein distance
if (errors.Suggestions.Count() == 1) 
{
    var incorrectTextRange = richTextBox.GetSpellingErrorRange(errorPosition);
    var correctText = error.Suggestions.First();
    var incorrectText = incorrectTextRange.Text;

    // Correct the text with the chosen word...
    errors.Correct(correctText);
}

// Set caret position...