Question

I'd like to insert a FlowDocument (doc1) into another FlowDocument (doc2) at doc2's current Cursor Position.

I know I can get the Cursor position through CaretPosition of the RichTextBox the Document is in, and I can technically add a Block AFTER or BEFORE another Block, but I can't add it to a specified Cursor Position with the Blocks Property alone (and it's add methods).

I can add Inline elements, at least most of it's subclasses, at specified TextPointers, which would be what I want, but I can't add a Block to the Inlines of another block. Iterating over Blocks is not possible as well as the Base class "Block" does not contain any Inline store property. Trying to cast the Block to every possible specific Block Type doesn't seem like a good idea at all.

So, is there any easy and clean way to insert the entire Content of doc1 at the Cursor position of doc2?

Was it helpful?

Solution

OK, I found the solution apparently. Works with FlowDocuments as well, but I needed RTF there.

byte[] byteArray = Encoding.Default.GetBytes(rtfString);
MemoryStream stream = new MemoryStream(byteArray);
this.selectedRichTextBox.Selection.Load(stream, DataFormats.Rtf);
stream.Close();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top