【发布时间】:2016-05-20 16:54:31
【问题描述】:
我在 WPF 中有一个 RichTextBox (Name="txtGoTo"),我只需要第一个字符为红色(而其余字符为默认黑色)。
这是我尝试过的(在网上找到的),但它不起作用:
Dim rtb As RichTextBox = txtGoTo
Dim Text As String = New TextRange(rtb.Document.ContentStart, rtb.Document.ContentEnd).Text
If Not String.IsNullOrEmpty(Text) Then
Dim RangeAisle As TextPointer = rtb.Document.ContentStart
Dim RangeShelf As TextPointer = rtb.Document.ContentStart.GetPositionAtOffset(1)
Dim tr As New TextRange(RangeAisle, RangeShelf)
tr.ApplyPropertyValue(RichTextBox.ForegroundProperty, Brushes.Red)
End If
【问题讨论】: