How to implement a lazy loaded Silverlight data grid without swapping

Using the business application template from the newly released RIA services, you can see many examples using the data grid on top of the DomainDataSource in combination with the DataPager . The PageSize and LoadSize properties can be used to configure the amount of data that will be displayed on one page and the data that is preselected in the background.

Now I would like to have a data grid with a scroll bar and no pager. The underlying DomainDataSource should only load data that differs in the grid. It should start another download when the user scrolls to items that are not already in the data context. Is there an example implementation of how to do this?

+6
silverlight wcf-ria-services data-virtualization
source share
3 answers

I just posted a couple of blog posts ( Part 1 , Part 2 ) that give my solution to this problem. I also posted a sample on GitHub that implements my own VirtualCollection concept (I don’t know how this compares with the Infragistics control because I did not use this).

To show how easy it is to use, here are a few snippets from the example. First, here is how you use VirtualCollection , a class that coordinates data fetching:

 public class MainViewModel : ViewModel { private NetflixTitlesSource _source; public VirtualCollection<Title> Items { get; private set; } public MainViewModel() { _source = new NetflixTitlesSource(); Items = new VirtualCollection<Title>(_source, pageSize: 20, cachedPages: 5); } protected override void OnViewLoaded() { Items.Refresh(); } } 

In XAML, you simply bind the Items property to the ItemsSource property of a ListBox or DataGrid

For each data source, you must implement VirtualCollectionSource. Here, the two main NetflixTitlesSource methods are as follows:

 public class NetflixTitlesSource : VirtualCollectionSource<Title> { protected override Task<int> GetCount() { return GetQueryResults(0, 1, null) .ContinueWith(t => (int)t.Result.TotalCount, TaskContinuationOptions.ExecuteSynchronously); } protected override Task<IList<Title>> GetPageAsyncOverride(int start, int pageSize, IList<SortDescription> sortDescriptions) { return GetQueryResults(start, pageSize, sortDescriptions) .ContinueWith(t => (IList<Title>)((IEnumerable<Title>)t.Result).ToList(), TaskContinuationOptions.ExecuteSynchronously); } private Task<QueryOperationResponse<Title>> GetQueryResults(int start, int pageSize, IList<SortDescription> sortDescriptions) { // code to query the Netflix OData API } } 
+1
source share

Check out the work that Be Stolnitz did on her blog. Although this is not a direct answer to your question, she wrote quite a lot about the user interface and data visualization. Here is a link from her blog that I think will help you get started:

Data Virtualization: http://bea.stollnitz.com/blog/?p=344

NTN!
Chris

+1
source share

It was called covert paging. Component One has a sample of its DataGrid that uses Stealth Paging. As soon as you scroll down, it will get the next page.

http://demo.componentone.com/Silverlight/ControlExplorer/#DataGrid/Stealth%20Paging

Shows a demo, and you can download a sample that shows the code.

Hope this helps,

Greg

+1
source share

All Articles