The typical ListView GroupStyle with an Expander looks roughly like this:
<ListView.GroupStyle>
<GroupStyle>
<GroupStyle.ContainerStyle>
<Style TargetType="{x:Type GroupItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GroupItem}">
<Expander>
<Expander.Header>
<TextBlock Text="{Binding Path=Name}" />
</Expander.Header>
<Expander.Content>
<ItemsPresenter />
</Expander.Content>
</Expander>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</GroupStyle.ContainerStyle>
</GroupStyle>
</ListView.GroupStyle>
The TextBlock is bound to Name, which seems to produce the value of the GroupItem's object whose propertyName was passed into the PropertyGroupDescription which was added to a ListCollectionView's GroupDescriptions Collection (whew):
class MyClass
{
public int Id { get; set; }
public int FullName { get; set; }
public string GroupName { get; set; } // used to group MyClass objects
}
MyView.GroupDescriptions.Add(new PropertyGroupDescription("GroupName"));
How can I get my ListView's group heading to display a property other than GroupName? The point I'm making is that GroupName is useful to split my objects into groups, but is not necessarily the name I wish to use for the headers of said groups.
CollectionViewGroup.Name Property is of type object. This means your GroupName property doesn't have to be a string. Try something like this
class MyClass
{
...
public MyGroup GroupName { get; set; } // used to group MyClass objects
}
class MyGroup
{
public string HeaderText { get; set; }
// maybe you will need an additional property to make this object
// unique for grouping (e.g. for different groups with same HeaderText)
}
.
<Expander.Header>
<TextBlock Text="{Binding Path=Name.HeaderText}" />
</Expander.Header>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With