Sample Code: Data Virtualization Using a Web Service with Xceed DataGrid for WPF

I got a few requests for sample code to my post about Data Virtualization with Xceed DataGrid for WPF. I have come up with a sample Visual Studio 2008 solution for this. You can download the solution at: http://www.aocampo.com/Downloads/DataVirtSample.zip.

The solution contains:

  1. A sample WPF application project (DataVirtClient) that uses the Xceed DataGrid for WPF. You will need to set the Xceed DataGrid for WPF Professional Edition license key in the App.xaml.cs file to run the application.
  2. A sample ASP .Net web service project (DataVirtSvc) that is called by the WPF application. The web service serves as the data source for the data being virtualized in the WPF application.

Notes

  • I tried to make the sample as simple as possible. Hopefully, the simplified implementation will make understanding the technique easier. Having said this, note that this ‘bare bones’ sample is for demonstration purposes only and it is up to you to take the essence of the technique and refine it to fit your problem.
  • The main methods that the web service must provide are:
    • A method to provide the item count in a dataset
    • A method to provide a ‘page’ of a dataset
  • Main ingredients of data virtualization with the Xceed DataGrid for WPF:
    • Use a DataGridVirtualizingCollectionView as the control’s ItemsSource
    • Handle the QueryItemCount and QueryItems events of the DataGridVirtualizingCollectionView
      • Call the appropriate web service methods in these event handlers
      • In the QueryItems event, call the web method asynchronously
  • I mentioned using ASP .Net session state for my solution in my previous post. This sample does not do that as the web service uses a static data set. My guess is that you will have to implement some sort of persistence (like ASP .Net session state) or notification mechanism in your app if you will be working with non-static data. In the case of my previous post, I used ASP .Net session state to persist the dataset (of RSS feed items) that is currently bound to the datagrid to keep the dataset virtually static on the server (i.e., the server will work on the persisted dataset in session state instead of live data in the database that is prone to change every few minutes --- I know that this solution generally does not scale well but it is acceptable in my case).
  • The solution was built with version 3.1 of the Xceed DataGrid for WPF (version 3.2 was released recently).
«July»
SunMonTueWedThuFriSat
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678