我正在扩展WPF RichTextBox的功能。我希望在键入特定文本时使其变粗。我能够让某些文本加粗,但是接下来的文本也会变得加粗...
以下是我的代码示例:
我想要的是:
NOTBOLDED NOTBOLDED BOLDED NOTBOLDED
但我得到的是:
NOTBOLDED NOTBOLDED BOLDED NOTBOLDED
请注意,在输入时,它会变成粗体。
如何防止粗体单词后面的文本也变成粗体?
这不是重复的问题,因为提供链接的已接受解决方案仅适用于WinForms,其余解决方案仅适用于预设文本。
以下是我的代码示例:
private bool _Running = false;
void CustomRichTextBox_TextChange(object sender, TextChangedEventArgs e)
{
if(_Running)
return;
_Running = true;
//Logic to see if text detected
//Logic to get TextPointers
//Logic to get TextRange
var boldMe = new TextRange(textPointer1, textPointer2);
//Bold text
boldMe.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Bold);
_Running = false;
}
我想要的是:
NOTBOLDED NOTBOLDED BOLDED NOTBOLDED
但我得到的是:
NOTBOLDED NOTBOLDED BOLDED NOTBOLDED
请注意,在输入时,它会变成粗体。
如何防止粗体单词后面的文本也变成粗体?
这不是重复的问题,因为提供链接的已接受解决方案仅适用于WinForms,其余解决方案仅适用于预设文本。