private async void Totaux_Loaded(object sender, RoutedEventArgs e)
{
observableCollection = new ObservableCollection <Prod>();
DataHolder = new DataHolder();
await DataHolder.Init();
foreach (var data in DataHolder.Products)
{
observableCollection.Add(new Prod()
{
Product = data, Quant = 0, SlicedQuant = 0
});
}
foreach (var client in DataHolder.Clients)
{
foreach (var pr in client.Products)
{
//https://stackoverflow.com/questions/6781192/how-do-i-update-a-single-item-in-an-observablecollection-class
var prod = observableCollection.First(tmp => tmp.Product.Name == pr.Product.Name);
var idx = observableCollection.IndexOf(prod);
prod.Quant += pr.Quantity;
if (pr.Sliced)
{
prod.SlicedQuant += pr.Quantity;
}
observableCollection[idx] = prod;
}
}
Total.ItemsSource = observableCollection;
}