CollectionViewSource にバインドされた ItemControl があります。ItemControl 項目はグループ化されてから、データ テンプレートに表示されます。私が達成したいのは次のようなものです:
-A--------------
| Aa... |
| Aaaa... |
----------------
-B--------------
| Bb... |
| Bbb... |
----------------
これが私のコードです:
XAML
<CollectionViewSource x:Key="itembyAlpha" Source="{Binding listItem}">
<CollectionViewSource.GroupDescriptions>
<PropertyGroupDescription PropertyName="initial" />
</CollectionViewSource.GroupDescriptions>
</CollectionViewSource>
<ItemsControl ItemsSource="{Binding Source={StaticResource itembyAlpha}}">
<!--GroupStyle-->
<ItemsControl.GroupStyle>
<GroupStyle>
<GroupStyle.ContainerStyle>
<Style TargetType="{x:Type GroupItem}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GroupItem}">
<GroupBox Header="{Binding initial}">
<ItemsPresenter />
</GroupBox>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</GroupStyle.ContainerStyle>
</GroupStyle>
</ItemsControl.GroupStyle>
<!--Item Template-->
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding title}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
C#
public class Movie
{
public string id { get; set; }
public string title { get; set; }
public string initial { get; set; }
}
List<Movie> lst;
public List<Movie> listItem
{
get { return lst; }
set { lst = value; }
}
私の問題は、コードのこの部分が機能しないようです:
<GroupBox Header="{Binding initial}">
<ItemsPresenter />
</GroupBox>
プログラムを実行すると、結果は次のようになります。
- --------------
| Aa... |
| Aaaa... |
----------------
- --------------
| Bb... |
| Bbb... |
----------------
GroupBox のヘッダーが空白です。バインドがうまくいかないようです。誰か助けてくれませんか...
前にありがとう。