Expander を使用した典型的な ListView GroupStyle は、おおよそ次のようになります。
<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>
TextBlock は Name にバインドされています。これは、ListCollectionView の GroupDescriptions コレクションに追加された PropertyGroupDescription に propertyName が渡された GroupItem のオブジェクトの値を生成するようです (おっと):
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"));
ListView のグループ見出しに GroupName 以外のプロパティを表示するにはどうすればよいですか? 私が指摘しているのは、GroupName はオブジェクトをグループに分割するのに便利ですが、必ずしもそのグループのヘッダーに使用したい名前ではないということです。