Can we use domain model at UI layer in MVVM pattern
Can I use domain model at UI layer instead of view model in some of the views. If No开发者_JAVA百科. Why shouldn't I use?
If you are exposing some model objects in a list to an ItemsSource, I think this completely fine. I generally take the approach to only wrap a model such as this in a ViewModel when:
- I need custom formatting of a property that seems cleaner to do in a ViewModel than using IValueConverter
- I need to put a method/ICommand on the object
I wouldn't do it if the models are somehow bound to a View not in an ItemsSource such as a Window or UserControl, however. If you are finding you have ViewModels that don't have very many properties or methods/ICommand, then you need to merge several into the one ViewModel.
精彩评论