2
我正在WPF RichTextBox中工作。我突出顯示了每個單詞,使用下面的code.its工作正常。但該單詞包含連字符的意思是,突出顯示的單詞之間有一些細線連字符。如果WPF Richtextbox突出顯示的單詞包含連字符,單詞中顯示的細線?
string SelectHighlightWord(RichTextBox rtb, int offset, int length)
{
TextRange fullRange = new TextRange(rtb.Document.ContentStart, rtb.Document.ContentEnd);
fullRange.ClearAllProperties();
TextPointer startSelect = fullRange.Start.GetPositionAtOffset(offset);
TextPointer endSelect = startSelect.GetPositionAtOffset(length);
TextRange textRange = rtb.Selection;
textRange.Select(startSelect, endSelect);
textRange.ApplyPropertyValue(TextElement.BackgroundProperty, new SolidColorBrush(m_backgroundColor));
textRange.ApplyPropertyValue(TextElement.ForegroundProperty, new SolidColorBrush(m_foregroundColor));
FrameworkContentElement fce = (startSelect.Parent as FrameworkContentElement);
if (fce != null)
{
fce.BringIntoView();
}
return rtb.Selection.Text;
}
注意:爲了更好的理解,我添加了圖片。
爲什麼這會發生。所有人? –