Use of ICollectionView and Conventions?

Aug 12, 2010 at 6:31 PM


I've found an interesting situation.  On my ViewModel if I expose a property ObservableCollection<MyViewModel> Results { get; private ;set} and then put a ListBox in my corresponding View and name it "Results" everything shows up in the ListBox as expected.  It takes into account the bool IsVisibleProperty on MyViewModel (with corresponding Grid named "IsVisible" in my View), I can step through the getter in the debugger and it gets called just fine, and sure enough the UI doesn't display a certain subset of MyViewModels in that ListBox.  So that all makes sense.

But it I instead expose ICollectionView Results all of the MyViewModels show up.  In the ViewModel I new up a CollectionViewSource, and then set its source to a new ObservableCollection<MyViewModel>, and then I set Results = collectionViewSource.View and notify that the Results property changed.  But the getter never gets called on the IsVisibleProperty on MyViewModel.

I am wanting to use ICollectionView only for the support for CurrentItem because I've got another ListBox and I want the CurrentItem for both of them to be the same.

I'm assuming this is due to the fact that the ObservableCollection is a generic so Caliburn.Micro can figure out exactly what type is inside the collection and then iterate over the various properties on that type, but in the case of the non-generic ICollectionView it cannot.

Thoughts about approaches for using ICollectionView with ViewModels?

Aug 12, 2010 at 6:58 PM

Disregard post.  I figured out my problem, once I started binding my ListBox to ICollectionView instead of ObservableCollection<T> I added in a DisplayMemeberPath on the list box and thus was binding to that rather than to the actual ViewModel itself, thus the visibility code I wrote was never getting called. 


My bad.