Answer the question
In order to leave comments, you need to log in
How to get (create) a collection that contains a "computed property" in the ViewModel class from the base collection in the Model?
I ask for help with MVVM, namely with the output of a collection that contains a "computed property" in the ViewModel class (inherited from a class from Model), which is not in the Model class. There is already a completed collection at the entrance. I reviewed more than 50 MVVM examples, all I saw was using a class from a model. In this case, everything is simple. And in real systems there may be several Views and each may contain similar data but with different calculated properties. Roughly speaking, I need Downcasting of the collection, or it is also called contravariance, and I need to save the binding so that the data is updated when the underlying collection changes, but it is not completely replaced.
For example, the Model has a Person class with the properties Name, Surname, and there is an ObservableCollection PeopleModel collection.
The ViewModel has a PersonWithFullName class inherited from Person and containing the calculated property FullName, and accordingly there is an ObservableCollection People collection. And here is a discrepancy, the initial data for this collection must be taken from the collection from the ObservableCollection PeopleModel.
How is this thing done in real systems? Is it possible to completely manually reload the collection from the base to the inherited one and do this every time the code changes the data in the base? Maybe someone has an example or who will push in which direction to dig?
Answer the question
In order to leave comments, you need to log in
Perhaps you will pass the "ObservableCollection PeopleModel" collection to the ItemsControl, after which add an envelope to the ItemTemplate implementation that will combine the necessary properties into a single one and display it in the form specified by the same ItemTemplate
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question