Reputation: 2775
I am trying to group a list of items in a WPF list view - its working fine but I cant get the expanders header to show.
I set the group style as follows:
<!-- Styles the groups -->
<ListView.GroupStyle>
<GroupStyle>
<GroupStyle.ContainerStyle>
<Style TargetType="{x:Type GroupItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Expander BorderBrush="LightBlue"
BorderThickness="1"
IsExpanded="True"
Name="groupExpander"
Header="{Binding Family}">
<ItemsPresenter />
</Expander>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</GroupStyle.ContainerStyle>
</GroupStyle>
</ListView.GroupStyle>
and the list view items source is bound in the code behind:
//group by shape family
CollectionView view = (CollectionView)CollectionViewSource.GetDefaultView(GetShapes());
PropertyGroupDescription groupDescription = new PropertyGroupDescription("Family");
view.GroupDescriptions.Add(groupDescription);
ImagesListView.ItemsSource = view;
And finally I am binding to a List of this object (I want to group on the family field with this string appearing in the group header:
public class Shape
{
public int ID { get; private set; }
public byte[] Image { get; private set; }
public string Description { get; private set; }
public string Family { get; private set; }
}
What am I not doing or doing wrong?
Upvotes: 0
Views: 544
Reputation: 33364
You need to change
Header="{Binding Family}"
to
Header="{Binding Name}"
Each group is a CollectionViewGroup
where Name
is the value that you group by
Upvotes: 2