Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The only situation, when you might need the two-way synchronization, is when the control that you use to visualize your collection of VMs does not let you know of user's intention to create or remove an item. I.e. the control deals directly with your collection of VMs and the ONLY way you know the item has been added/removed, is by monitoring the collection of VMs. If this is not the case then you can implement one way sync and add/remove items directly on model's collection.</p> <blockquote> <p>EDIT: Take for example WPF DataGrid control bound to observable collection of ItemViewModels. If its CanUserAddRows property is set to true and the user starts typing in the empty row at the bottom, the DataGrid will use default constructor of your ItemViewModel to create a loose item and then will add it to the collection. There is no indication from DG that it wants to add an item the collection.c I can't think of any other control that is complicated enough to be able to add items to collection on its own.<BR> The opposite scenario is when you have ListView bound to your collection and a command which indicates user's intention to add new item - then in command handler you simply add new item to DataModel and let the one-way sync do the rest of the job. In this case ListView is not able to add to the collection it presents.</p> </blockquote> <p>As to the sync process itself, look at <a href="http://bindablelinq.codeplex.com/" rel="nofollow noreferrer">Bindable LINQ</a> project - it can minimize the amount code and improve readability. For example the code Tom posted will translate into something like this:</p> <pre><code>class ViewModel { public Model Model; public ObservableCollection&lt;FooView&gt; Foos; public ViewModel() { Foos = from foo in Model.Foos.AsBindable() select new FooView(foo); } } </code></pre> <blockquote> <p>EDIT 2: After using B-LINQ for some time now I should say that you might have performance issues with it. I have used it to synchronize relatively big collections (hundreds of elements) collections with tens of elements being added and removed every second and I had to give it up and implement synchronization the way Tom had suggested.<BR> I still use B-LINQ though in those parts of the project where collections are small and performance is not an issue.</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload