Freigeben über


CollectionView

CollectionView is a very interesting construct.  After including it in my ViewModel I meant to quickly blog about the usage...but when I started thinking about it and reading a bit more about it, it becomes even more interesting.  Lots of good blogging.  However, while I think about it, let me quickly make my original point.

The Model has a simple List.  CollectionView wraps a Collection and adds concepts like selection, sorting and filtering to it and supports the INotify... goodness that data binding wants in order to do a really good job.  So, CollectionView is a construct that wraps a Model class and adapts it for data binding from the UI.  Uh...sounds like a ViewModel!

WPF does not use the terminology of M-V-VM, but it repeatedly uses the pattern.  CollectionView is a fine class name, but in very strict terms it isn't part of the View!  A CollectionView implies it has UI. 

If you really want to understand the M-V-VM pattern, there is no better place to start than to study how CollectionView adapts a Collection to be presented in the UI using data binding. 

Going to visit the in-laws, so blogging will be sporatic for awhile.

Comments

  • Anonymous
    March 07, 2006
    John,  

    This mirrors the concepts in System.Data of DataTable and DataView, where a DataView adds sorting and filtering on top of DataTable.

    It's almost like a mini MVC model within the viewmodel - in there, you've got the DataTable (the Model), then you can have N DataViews "showing" different selections/sorts/etc on the underlying Table.  Update the table once, and all bound DataViews update accordingly.  Hence, DataView.

    Sounds like CollectionView is analagous.
  • Anonymous
    March 11, 2006
    I am not familiar with CollectionView ... do you have any links that would point the un-initiatied in the right direction?
  • Anonymous
    March 13, 2006
    John Gossman has posted the first part of his long-awaited example of a Model-View-ModelView architecture,...