flowdocument - 在末尾插入富文本,在插入点上方创建额外的段落分隔符

时间:2022-09-13 00:18:58

I am creating a flowdocument that consists of multiple records. Each record contains two tables at the top, and then some rich text that I'm pulling out of a database. The code that appends the rich text is found below (cp.Comments contains the rtf tagged text).

我正在创建一个由多个记录组成的flowdocument。每条记录在顶部包含两个表,然后是一些我从数据库中提取的富文本。附加富文本的代码位于下面(cp.Comments包含rtf标记文本)。

Dim tr As TextRange
Dim arr() As Byte

Using ms As New System.IO.MemoryStream
  arr = (New System.Text.UTF8Encoding).GetBytes(cp.Comments)
  ms.Write(arr, 0, arr.Length)
  ms.Seek(0, IO.SeekOrigin.Begin)

  tr = New TextRange(fd.ContentEnd, fd.ContentEnd)   'add to end
  tr.Load(ms, DataFormats.Rtf)
End Using

The flowdocument renders the first of the records correctly, but all subsequent records are rendered with a break between the first and the second table. What is the most odd is that I'm rendering the 2 tables before importing the RTF, but the RTF is somehow affecting the spacing between the tables anyway.

flowdocument正确呈现第一个记录,但所有后续记录都在第一个和第二个表之间中断。最奇怪的是我在导入RTF之前渲染了2个表,但RTF无论如何都会以某种方式影响表之间的间距。

fd = new FlowDocument

for each cp in SomeCollection

   fdtemp = New FlowDocument

   CreateFirstTable(cp, fdtemp)
   CreateSecondTable(cp, fdtemp)
   AddRTF(cp, fdtemp)

   FlowDocumentUtils.AddDocument(fdtemp, fd)

next

The problem isn't something related to the data in the first element of the collection - if I tell the rendering to skip the rendering of the first record, then the second record renders ok, but the rest contain the extra spacing.

问题不在于集合的第一个元素中的数据 - 如果我告诉渲染跳过第一个记录的渲染,那么第二个记录渲染正常,但其余的包含额外的间距。

Note: the problem is definitely related to the rich text insertion - if I comment out the AddRTF call, then all the tables are correctly rendered smashed together. (table margins are all set to (0,0,0,0))

注意:问题肯定与富文本插入有关 - 如果我注释掉AddRTF调用,那么所有表都被正确地渲染在一起。 (表边距都设置为(0,0,0,0))

Has anyone ever seen this?

有没有人见过这个?

1 个解决方案

#1


1  

Have you checked out the solutions from this other question:

你有没有检查过这个问题的解决方案:

Also, it appears that you have two separate methods:

此外,您似乎有两种不同的方法:

CreateFirstTable(cp, fdtemp)
CreateSecondTable(cp, fdtemp)

I suspect that the difference between how these two methods are operating is where the problem is, but w/out knowing what they're really doing, I can only speculate.

我怀疑这两种方法的运作方式之间的区别在于问题所在,但是我知道他们真正在做什么,我只能推测。

#1


1  

Have you checked out the solutions from this other question:

你有没有检查过这个问题的解决方案:

Also, it appears that you have two separate methods:

此外,您似乎有两种不同的方法:

CreateFirstTable(cp, fdtemp)
CreateSecondTable(cp, fdtemp)

I suspect that the difference between how these two methods are operating is where the problem is, but w/out knowing what they're really doing, I can only speculate.

我怀疑这两种方法的运作方式之间的区别在于问题所在,但是我知道他们真正在做什么,我只能推测。