I have some data that I want to present in a FlowDocument
. This will basically be a view that explains the data in a friendly way, with section headers, paragraphs of text, etc., and which I will display in a FlowDocumentScrollViewer.
To this end, I would like to create a bulleted list (<List>
) out of the contents of an ObservableCollection
. I know how to do that with ItemsControl
, but how do I do it for ListItem
elements in a FlowDocument
, since they're part of the TextElement
class hierarchy rather than the Control
hierarchy? Is there an equivalent of ItemsControl
for text content inside a TextBlock
or FlowDocument
?
Edit: The article Sergey linked to is the perfect starting point. The only problem is that the article's code can only use a Section
or a TableRowGroup
as the items panel, and doesn't yet support using a <List>
. But that was trivial to fix -- just a matter of adding this code at the end of ItemsContent.GenerateContent
, just before the final else
:
else if (panel is List)
((List) panel).ListItems.Add((ListItem) element);
What you are looking for is possible, but requires significant amount of coding. Fortunately, Vincent Van Den Berghe posted a nice article on the MSDN describing how to Create Flexible UIs With Flow Documents And Data Binding , including the code!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With