1

我想要一个 ListView,它的项目类似于 Microsoft Outlook 收件箱,项目由 Conversations 排列(见附图)。项目可以是包含对话主题的简单文本块(在照片上,这是蓝线),也可以包含由 ListView 标题指定的电子邮件信息。最好是带有对话主题的项目是按钮,这样对话中的电子邮件就可以通过按下此按钮来显示或隐藏。

任何想法我怎样才能做到这一点?我是否指定两个 ListViewItem 模板?如果是,我如何在代码中告诉每个项目使用哪个模板?

任何帮助将不胜感激!!问候, 格雷戈尔

替代文字 http://img401.yfrog.com/img401/1719/inboxy.png

4

2 回答 2

2

您应该查看DataTemplateSelector。只是谷歌它。

这个想法是这样的。

  1. 您将在 XAML 中定义 2-3 个模板
  2. 创建一个派生自 DataTemplateSelector 的类,并基于 field/typeof 对象,您将返回适当的模板
于 2010-05-04T10:29:50.447 回答
1

The concept used in your screenshot is called Grouping. You can easily use grouping if you have a ListCollectionView as your ItemsSource. You then need to specify several GroupDescriptions for the ListCollectionView's GroupDescriptions property.

To define how these groups look like, you might have a look at this SO post: How do I group items in a WPF ListView. Other blog posts of interest might be: Bea Stollnitz: How can I do custom Grouping?, and Bea Stollnitz: How do I sort groups of data items?

In your scenario you would use the title of your email conversation as the group header, and maybe some additional data.

于 2010-05-04T10:38:37.370 回答