Home > Net >  When using DataTemplate in mvvm, does the view need to know the model?
When using DataTemplate in mvvm, does the view need to know the model?

Time:07-06

enter image description here

But, as above, if the view knows the model, then the structure is: enter image description here

Can we really say that the view doesn't know the model?

Assuming it knows, is there a way to "completely" isolate the view so that it doesn't know the model?

CodePudding user response:

It depends on how much you are really willing to work on separation! All the examples in tutorials are not made to make full separation, they just wanna show working example.

If you use your domain models inside the ViewModel then the View knows about them. If you need to separate that - then u gonna have mapper that will map your domain models into the ViewModels that are only known to View!

The idea for MVVM is that you can swap your view easy and to have more control inside the ViewModel iteself.

Let's assume you have your Customer Order domain objects with logic inside of them , if u wanna present them to the View you gonna have CustomerViewModel and OrderViewModel which will be mapped from domain objects. And your OrderDetailsViewModel will be :

public class OrderDetailsViewModel

 { 
   public class CustomerViewModel {get; set;}
   public class OrderViewModel {get; set;}
 }
  • Related