(因为这个问题一直没有得到任何答复,我重新措辞)WPF中丰富的文本框中删除隐藏字符
在我的申请,我有拥有丰富的文本框的对话框中,盒子里充满了从Twitter收集的Tweet。使用推文实体,我对推文进行格式化,以便在推文,提及和主题标签中包含内联超链接。但是,超链接永远无法正确定位;总是2或3个字符太快太远。
这是我使用设置在格式文本框中的文本代码:
TweetText.Document.ContentEnd.InsertTextInRun(Status.Text)
Dim FlowDocument As FlowDocument = TweetText.Document
If LinkEntity.Count > 0 Then
For Each Entity As Entities.TwitterUrlEntity In LinkEntity
Dim Start As TextPointer = FlowDocument.ContentStart
Dim StartPosition As TextPointer
Dim EndPosition As TextPointer
If Entity.StartIndex = 0 Then
StartPosition = Start.GetPositionAtOffset(Entity.StartIndex)
Else
StartPosition = Start.GetPositionAtOffset(Entity.StartIndex)
End If
EndPosition = Start.GetPositionAtOffset(Entity.StartIndex + Entity.DisplayUrl.Length, LogicalDirection.Backward)
Dim h As New Hyperlink(StartPosition, EndPosition)
AddHandler h.MouseLeftButtonDown, AddressOf Hyperclick_Link
h.NavigateUri = New Uri(Entity.Url)
h.Cursor = Cursors.Hand
Next
End If
'I have the other entities here, they have very similar code'
TweetText.Document = FlowDocument
这是我的格式文本框XAML:
<RichTextBox Name="TweetText" Margin="5" FontSize="14" BorderThickness="0" IsReadOnly="True" />
这是输出:
推文实体对每个实体都有适当的索引,但我确实认为Ri ch文本框具有导致此偏移量的隐藏字符。
好吧,我会试试看。我现在远离Windows电脑,但当我回到一台电脑时,我会测试你的理论。谢谢! –