我在MSDN上看到.NET 4.6.1现在支持自动更正。%appdata%/Microsoft/Spelling//中的文件是自动创建的,我在default.acl中添加了以下行(文件仍然是UTF-16和BOM):
tramampoline|trampoline我已经将项目设置为目标4.6.1,并在SpellCheck上启用了RichTextBox:
<RichTextBox SpellCheck.IsEnabled="True" Language="de-DE"/>当按通常的方式输入错误时,它会突出显示单词,但不会发生自动更正。
我在这里错过了什么?我不太明白这张便条:
注意: WPF拼写检查API不直接支持这些新的文件格式,应用程序中提供给WPF的自定义字典应该继续使用.lex文件。
发布于 2019-03-08 17:36:06
我知道这是旧的,但据我所知,您需要自己处理AutoCorrect (如果我错了,请用一个示例纠正我)。您可以这样做:
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,而是在您希望更正的单词末尾使用一个文本指针。如果您的文本指针/插入符号位于一个奇怪的位置(例如,20个空白空间的末尾),则GetNextSpellingErrorPosition方法可能需要60秒才能返回(取决于您的RTB中的硬件/字数)。
https://stackoverflow.com/questions/34335108
复制相似问题