Having hard time binding a list to the datagrid:
XAML:
<DataGrid Name="dgProductList"
ItemsSource="{Binding ProductList}">
<DataGridTextColumn Binding="{Binding ProductName}" Header="Item" />
<DataGridTextColumn Binding="{Binding Quantity}" Header="Qty" />
<DataGridTextColumn Binding="{Binding TotalPrice}" Header="Price" />
<DataGridTemplateColumn Width="*">
Code behind:
public IList<SalesItem> ProductList = new List<SalesItem>();
public void LoadProduct(Product product)
{
SalesItem item = new SalesItem { ProductName = product.Name, Quantity = 1, TotalPrice = product.Price };
ProductList.Add(item);
}
It does not load.
Thank you.
The dataGrid won’t know when the ProductList is updated… make a ObservableCollection like this:
EDIT:
Is the binding working at all? Name your control/window Root and bind to that element