DataGrid paging in Silverlight (MVVM)
DataGrid paging in Silverlight (MVVM)
This has been explained in several blog posts and tutorials, but I see newbie’s, still searching and asking questions related to this. So here, I have created a simple sample for you
Silverlight 4 has a client side pager control. To make it work properly, you need to do is to use proper data types and it bind correctly
I have a DataGrid, in the view (No code in the code behind); as you can see in the source code, a Mode, Entity and a ViewModel is created, view model holds the business logic for the XAML (Nothing much, just a sample collection), the model provides the data (just one method that returns a set of values to the collection) and the entity provides the definition of the employee class
In the XAML, I have a DataGrid in place, which has the ItemsSource set as the Employees and a Pager control, wherein the Source is the Employess (ItemsSource of the DataGrid); now, let’s check the ViewModel; I have a private member of type ObservableCollection of Employee (Employee Entity Class) which holds the details of the employees, and a Public Property which is of type PagedCollectionView. This provides the data to the DataGrid in the XAML. In fact, the PagedCollectionView type holds the key and provides the paging method for the XAML. The data for the collection comes from a Model class.
Download source code
Comments
Post a Comment