Grids with ViewModels - WPF

Sorry if this has already been asked, but I just want to make sure I'm doing it right.

If I have a domian object that says 10 properties on it. I have a grid in my main form that I want to show almost all the properties of the model.

I created a viewmodel to wrap a domain object that will be displayed in a gridview, but then I have to open all the properties again. I just feel snapped right to the model, as the review model seems dirty and slightly distorts the target.

So, for example, I do not really like this:

 {Binding DomainObject.Property}

where DomainObject is a property in my view model.

So, my main question is: should I show all the properties of the model through the view model only for binding to the grid?

EDIT: For additional information only, domian objects are LINQ-To-SQL objects, so I don't think they implement INotifyPropertyChanged, but I'm not sure.

+3
source share
3 answers

Some people will say that it does not matter, others say that it is. I am in the last camp for these reasons:

  • You increase view dependencies, since now it depends on the data model, and not just on the presentation model.
  • Developers are required to know the properties and structure of your data model.
  • You create more work for (almost inevitable) refactoring when you decide that you need a layer of indirection for formatting, validation, or whatever might be.
  • ,

, , , , , .

PS. , , ICustomTypeDescriptor, . , , , , .

+3

, INotifyPropertyChanged, ViewModel. , , : MVVM , , ...

+1

I think this is a matter of personal preference. I seem to think it’s great to show the model in one object from the ViewModel. Reproducing all the model properties in the ViewModel results in a lot of code.

However, this only works if your model implements change notifications to work with data binding.

0
source

Source: https://habr.com/ru/post/1714406/


All Articles