Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

How to: convert Blocks to Inlines and Inlines to Blocks?

$
0
0

Hello,

I am implementing a simple editor that should allow user to place some objects on a page (at fixed locations). Those objects should include: Images, Lines and other graphics objects (like Rectangles) and Formatted text blocks. Than such page should be understood as a template connecting it with some type of a database to produce a set of similar pages.

Images could be different (Urls taken from a database) and parts of text fields could be taken from the database too.

Text fields has to be formatted, so it would be possible to, for example, enter a text like this:

fixed header: database field

and center this text inside given rectangle given to it (allowing it to wrap to second line if needed).

Documents have to be writtable too, so I need to be able to serialize them.

I have already solved problems with serializing FixedDocuments by hand (not to XPS) so that they could be opened later and editor would be able to continue the work on them.

There were some problems with serialization that ended in a conclusion that I can't put RichTextBox with FlowDocument inside my FixedPage - such contruct would not be serializable with XamlObjectReader / XamlXmlWriter - and only those functions allow me to plug my code inside Node Loop (I need Node Loop to properly serialize Images and attached properites used by FixedPage).

So I can't directly use RichTextBox inside my document, but I need it to allow editing of text inside my TextBlocks. In short I have to be able to convert content of TextBlock into FlowDocument to allow editing and FlowDocument back into TextBlock if changes are accepted.

TextBlock uses Inlines and FlowDocument uses Blocks. At first I thought I could export data from one of those controls to RTF and import it to the other, but it looks like even if TextBlock could be used together with TextRange, TextRange.Load function would not be able to Load an RTF into TextBlock.

So I ended in a position where I think the only solution left is convertion of Inlines into Blocks and Blocks back into Inlines.

Any hints how to do that? I don't really need to support images inside FlowDocuments. If user needs to put image on a page, sie should put than as separate object, not inside a TextBlock.


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>