开发者

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:

  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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜