问题描述
我有一些我想在 FlowDocument
中呈现的数据。这将基本上是一种以友好的方式解释数据的视图,其中包含节头,文本段落等,我将在FlowDocumentScrollViewer中显示。
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.
为此,我想在 ObservableCollection
< List> ) >。我知道如何使用 ItemsControl
,但是如何在 ListItem
元素中执行 FlowDocument
,因为它们是 TextElement
类层次结构的一部分,而不是 Control
层次结构? TextBlock
或 FlowDocument $ c中的文本内容相当于
ItemsControl
$ c>?
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
?
编辑 Sergey linked to是完美的起点。唯一的问题是,文章的代码只能使用 Section
或 TableRowGroup
作为项目面板,不支持使用< List>
。但是这很简单,只是在 ItemsContent.GenerateContent
的末尾添加这个代码,就在最后的 else $之前
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);
推荐答案
你正在寻找的是可能的,但需要很大的编码量。幸运的是,Vincent Van Den Berghe在MSDN上发表了一篇很好的文章,介绍如何,包括代码!
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!
这篇关于是否有与文本内容相当的ItemsControl?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!