tags:

views:

35

answers:

1

I have a set of data that I'd like to present via a WPF ListView in this way:

Column1   Column2   Column3
--GroupName1--
Item1     part2     part3
Item2     part2     part3
--GroupName2--
Item3     part2     part3
Item4     long_text_in_both_columns
Item5     part2     part3
--GroupName1--
Item6     part2     part3
Item7     long_text_in_both_columns
--GroupName3--
Item8     part2     part3

I'd like to color the groups such that each group name has an associated color. Note that in the above list, there are two instances of "GroupName1", and both should be the same color. I am starting by working with this basic sample: http://msdn.microsoft.com/en-us/library/ms771309(VS.90).aspx

Specifically:
-How can I have two groups with the same name, but differing items? (Possibly something like a hidden "group ID" that differs from the displayed "group name"?)
-How can I style each group by name?

(Note that all of the items are always displayed in order, and options other than groups would be fine too.)

A: 

Your question is vague but i will try my best to answer them.

  1. How can I have two groups with the same name, but differing items? (Possibly something like a hidden "group ID" that differs from the displayed "group name"?)

How have you identified that the items in each group belong there in the first place? In the example of "Group 1", they will always be in the same group if you decide to group the items by a defined group description (your example uses "GroupName")

  1. How can I style each group by name?

Grouping styles can be defined in the following way.

<Style TargetType="{x:Type GroupItem}" >
    <Setter Property="Template" >
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type GroupItem}" >
                <GroupBox Header="{Binding Name}" />
                    // define style here...
                </GroupBox >
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

// ...
<ListView.GroupStyle>
    <GroupStyle />
</ListView.GroupStyle>
// ...
Tri Q
1. Yes, I know which items belong to which groups, they just need to show up in the order listed with the display names shown. Sometimes the display names are identical.
PeteVasi
2. I understand how to style a group, but what I want is to have each different group (by display name) have a different style. One style per display group.
PeteVasi