Søren Lorentzen
Søren Lorentzen

Reputation: 866

ComboBox in DataGridTemplateColumn. Binding not working

In my WPF window, I have declared the following:

public List<Brand> BrandList;

and then in the constructor, the list is populated:

BrandList = new List<Brand>(EntityDao.GetInstance().GetProducts().Select(p => p.Brand).Distinct().OrderBy(b => b.Name));

Then in my XAML code, I have declared a 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>

The problem is that my comboboxes are empty. By debugging, I have verified that the BrandList object holds more than 80 objects, all of which have defined a ToString() method.

The ItemsSource of the DataGrid is a simple ObservableCollection.

Any ideas?

Upvotes: 1

Views: 987

Answers (1)

user1064519
user1064519

Reputation: 2190

Binding works with properties, and you declared a public member. You should define your list like this:

public List<Brand> BrandList { get;set;}

Upvotes: 2

Related Questions