ICollectionViewin the ViewModel?

Topics: Prism v4 - Silverlight 4, Prism v4 - WPF 4
May 24, 2011 at 8:20 PM

Wanting to learn MVVM and WPF I've been reading up and then came to the Prism PDF documentation.

In here (page 58) it talks about using ICollectionView inside a view model - but then says you need a different implementation for Silverlight (PagedCollectionView) and WPF (e.g. ListCollectionView)

I thought one of the goals of ViewModel was to be platform agnostic so it could be used for either Silverlight or WPF?

May 24, 2011 at 8:42 PM
Edited May 24, 2011 at 8:44 PM


Multi-targeting code between a Silverlight and WPF application is one of Prism's objectives; however, due to the differences between the platforms, the implementations of ICollectionView need to be different. Therefore, one possible way to achieve a platform-agnostic solution in this case would be to use conditional compilation directives to create a PagedCollectionView in case your class is being compiled in Silverlight, and a ListCollectionView otherwise.

To illustrate this:


public class SomeViewModel



ICollectionView collection;

public SomeViewModel()


#if SILVERLIGHT collection = new PagedCollectionView(); #else collection = new ListCollectionView(); #endif





Additionally, you might find the following chapter useful:

Chapter 10: Sharing Code Between Silverlight and WPF

I hope you find this helpful.

Guido Leandro Maliandi