MVVM should model items have INotify?
Very basic question but I am conflicted.
I have a viewmodel
The ui is a listview with items as itemsource and the items are shown with their details.
Now when I add to Items it will update the ui ofc, but when I change a property of an item I also want to show it in the ui. I can do this by adding
My only logical issue is that the HSItemFull is in the model. Whats the common way to handl this, is it stupid to add Observable property to model classes? The other way I see is to copy this item into one at viewmodel which seems more stupid.
5 Replies
Some time ago I've asked the same question here.
create a viewmodel for
HSItemFull
I can say that there's nothing wrong in making a model observable.
The viewmodel must inherently be observable, but it also contains business logic, commands and so on.
A model; however, should just represent data.
So, no business logic, no commands, no methods (apart from equality, cloning, etc.). This doesn't mean you can't make the model observable. Otherwise you'd be forced write a ton of unnecessary viewmodels that'd shadow your models, only to add observability.
In some cases this is a valid approach. E.g., a validated form for creating a record in the db
i wouldnt say a model has to just represent data
its just whatever the actual appolication layer is
a dto is what only represents data
but yeah you can make the model observable i think thats fine
altho id ask in #gui to see if they have another approach
Thanks for the answers