私の WPF ウィンドウで、次のように宣言しました。
public List<Brand> BrandList;
次に、コンストラクターで、リストにデータが入力されます。
BrandList = new List<Brand>(EntityDao.GetInstance().GetProducts().Select(p => p.Brand).Distinct().OrderBy(b => b.Name));
次に、XAML コードで DataGrid を宣言しました。
<DataGrid <!-- Properties omitted--> >
<DataGrid.Columns>
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox ItemsSource="{Binding Path=BrandList, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<!-- Other columns omitted -->
</DataGrid.Columns>
</DataGrid>
問題は、コンボボックスが空であることです。デバッグによって、BrandList
オブジェクトが 80 を超えるオブジェクトを保持し、そのすべてがToString()
メソッドを定義していることを確認しました。
DataGrid の ItemsSource は単純な ObservableCollection です。
何か案は?