Recently, I get my panties regarding view models (VM).
Like this guy , I came to the conclusion that the collections that I need to present on my virtual machine usually contain a different type for collections open on my business objects.
Therefore, there must be a bi-directional mapping or conversion between the two types. (To complicate the situation, in my project this data is “Live”, so as soon as you change the property, it will be transferred to other computers).
I can just handle this concept using a framework like Truss , although I suspect there will be an unpleasant surprise somewhere inside.
Not only objects need to be transformed, but synchronization between the two collections is required. (To complicate matters, I can think of cases where a VM collection can be a subset or a collection of collections of business objects, and not just 1: 1 synchronization).
I can see how to do one-way live synchronization using ObservableCollection replication or something like CLINQ.
Then the problem arises: what is the best way to create / delete items?
Bi-directinal sync does not seem to be present on maps - I have not found such examples, and the only class that supports anything like this is ListCollectionView. Would bidirectional synchronization be an even smart way to add back to a collection of business objects?
All the samples that I saw never seem to do this “complicated” thing.
So my question is: how do you solve this? Is there any technique for updating model collections from a virtual machine? What is the best overall approach to this?
design-patterns wpf mvvm
Schneider
source share