开发者

Can we use domain model at UI layer in MVVM pattern

开发者 https://www.devze.com 2023-04-09 13:54 出处:网络
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 th

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:

  1. I need custom formatting of a property that seems cleaner to do in a ViewModel than using IValueConverter
  2. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号