I have read that in MVVM the VM should know nothing about the view and view should not bind directly to the model, but should bind to the VM which forwards on properties from model and manipulates the model as required. So I guess the model classes do not need to implement INotifyProperty changed as this is handled by the view model.
This is all fine when there one of everything but I am not sure how to arrange things when there are parent child relationships. Say we have an Order object which has properties (customer name, address etc.) which are displayed on the order view. So an OrderView binds to an OrderViewModel which has a reference to an Order (model) object. Each Order object has a list of OrderItem (model) objects which has properties like item, quantity total etc.
Now the OrderView needs to display a list of OrderItems (say in a GridView) and so bind to a property called Items on the OrderView. What should the type of this property be? If it’s List then out view is binding directly to model object, which is against the principles I mentioned at the start and, our OrderItem object does implement INotifyPropertyChanged. Should the OrderItem be “wrapped” in some kind of VM object, and if so what should we call it – OrderItemViewModel? I’m not sure this is a good fit as is not the view model of an order item view – its just providing properties for the GridView to bind to, and that name conflicts with OrderItemViewModel class described below
Now lets say we have an OrderItemView which is a UserControl which is a child of the OrderView. Its role is to display the currently selected order item on the OrderView. Am I right is saying that It’s view model should be called OrderItemViewModel and it should have a reference to the currently selected order which is set by the OrderViewModel, so the OrderViewModel has knowledge of the OrderItem view model?