是否有与文本内容相当的ItemsControl? [英] Is there an ItemsControl equivalent for text content?

查看:112
本文介绍了是否有与文本内容相当的ItemsControl?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些我想在 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 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上发表了一篇很好的文章,介绍如何创建灵活的UI使用流文件和数据绑定,包括代码!

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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆