type here
Metaphorically, I have three classes: ShoppingCart
, ShoppingBag
, and Product
:
class ShoppingCart
{
public List<ShoppingBag> ShoppingBags { get; set; }
public ShoppingCart()
{
LoadShoppingBags();
}
}
class ShoppingBag
{
public List<Product> Products { get; set; }
public ShoppingBag()
{
LoadProducts();
}
}
class Product
{
}
I’ve have a view model as follows:
class ShoppingCartViewModel
{
ObservableCollection<ShoppingBag> ShoppingBags { get; set; }
public ShoppingCartViewModel()
{
GetShoppingCart();
ShoppingBags = ShoppingCart.ShoppingBags;
}
}
How do I observe List<Product> Products
without putting an ObservableCollection
in the ShoppingBag
model? I have done so and it works as expected, but I have this nagging thought that this is wrong (breaking the MVVM pattern and all that). I’ve seen various views on this topic on this forum with talks of ‘wrapper’ classes from some and others saying it’s ok.I haven’t seen any examples of two nested Lists. Is there an alternative to putting an observable collection in a model?