Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

flowdocument - inserting rich text at end creating extra paragraph breaks above insertion point

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).

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.

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))

Has anyone ever seen this?

like image 907
taglius Avatar asked Feb 01 '11 15:02

taglius


1 Answers

Have you checked out the solutions from this other question:

  • Adding text in a new line in WPF RichTextBox at runtime

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.

like image 148
Alexander Avatar answered Nov 15 '22 03:11

Alexander