我正在扩展WPF Richtextbox的功能。我想,当我键入它的某些文本变成黑体我能得到一定的文字加粗,但下面的粗体字文本也将成为加粗了在WPF RichTextBox中将特定文本设置为粗体
继承人我的代码示例:
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 加粗 NOTBOLDED
,但我得到什么:
NOTBOLDED NOTBOLDED BOLDED NOTBOLDED
**请注意,键入内容时会变成粗体。
如何防止粗体字后的文字变粗体?
不重复的问题,因为所提供的链接接受的解决方案是WinForms和其余为预设的文字。
[使特定文本在文本框中粗体显示]可能的重复(http://stackoverflow.com/questions/6403902/making-specific-text-bolded-in-a-textbox) –