using Datapager with MVVM

Nov 5, 2011 at 4:29 PM

Hi there!

first of all I have to say the Simple MVVM Toolkit is a really good framework! Especially the video tutorials are so helpful. But at the moment I'm trying to add a datapager into my silverlight app, which isn't as easy as i thought. This seems to be a general MVVM problem...after reading some really interesting approaches about how to bind a datapager using mvvm, I think this is one of the easiest and cleanest ways: http://blogs.msdn.com/b/kylemc/archive/2010/12/02/introducing-an-mvvm-friendly-domaindatasource-the-domaincollectionview.aspx

Currently I stored everything (DomainCollectionView; CollectionViewLoader etc) in the serviceAgent Class and the VM only acts as a proxy between View and ServiceAgent; that's not the proposed way of SimpleMVVM-Toolkit I think :-) But I don't know how to separate the both classes --> on the one hand I have to store the DomainCollectionView in the serviceAgent class, because I need to dynamically fill it with the results (depending on the current page / search text) but on the other hand, I should store the DomainCollectionView in the VM to access it from the View, right?

Do you have a general approach for using datapagers with SimpleMVVMToolkit?

Nov 6, 2011 at 1:16 PM

The DomainCollectionView is for use with WCF RIA Services, as a replacement for the DomainDataSource, which gave you drag and drop data binding but was not compatible with MVVM.  I haven't played around with it too much, but I believe that it's supposed to be in the View and/or ViewModel.  The job of the ServiceAgent is to supply data to the ViewModel -- that's it.

The DCV is basically a convenience to give you paging and sorting when dealing with a DomainContext that connects to a RIA Services project.  However, you can get the same functionality (albeit with a bit more work) using the PagedCollectionView instead of ObservableCollection<T> in the ViewModel (and this works for non-RIA Services projects too).  It's a bit of work to get things going, but there should be plenty of examples out there.  That will give you paging and sorting so that you can use a DataPager in the view.

Cheers,

Tony

Mar 6, 2012 at 12:15 PM

I know this discussion is old but for the benefit of those wondering for an example, have a look at http://blogs.msdn.com/b/avip/archive/2009/10/30/real-time-list-filtering-with-silverlight-mvvm-and-pagedcollectionview.aspx