Reputation: 866
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
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