1

私の 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 です。

何か案は?

4

1 に答える 1

2

バインドはプロパティで機能し、パブリック メンバーを宣言しました。次のようにリストを定義する必要があります。

public List<Brand> BrandList { get;set;}
于 2013-03-05T13:26:45.183 に答える