views:

169

answers:

2

Hi,

I would like to have a ListView that would have have items similar to Microsoft Outlook inbox with items arranged by Conversations (see the attached photo). An item can either be a simple textblock containing the topic of the conversation (on the photo this are the blue lines) or it can contain email information specified by the ListView's header. It would be best if the items with conversation topics would be push buttons so that emails inside that conversation could be shown or hidden by pressing this button.

Any ideas how can I achieve this? Do I specify two ListViewItem templates? If yes, how do I tell in the code which template to use for each item?

Any help will be GREATLY appreciated!! Regards, Gregor

alt text

+1  A: 

You should check out DataTemplateSelector. just google it.

The idea is this.

  1. You will define 2-3 templates in XAML
  2. create a class derived from DataTemplateSelector and based on a field/ typeof object you will return the appropriate template
SysAdmin
thanks, that's helpful.
Gregor
+1  A: 

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.

gehho
Thank you so much for this information. This worked perfectly for my purpose. Thank you!!
Gregor