6

Using the Business Application template from the brand new released RIA Services, you can see lots of examples using the data grid on top of a DomainDataSource in combination with a DataPager. The properties PageSize and LoadSize can be used to adjust the amount of data to be displayed in one page and the data that is prefetched in the background.

Now I'd like to have a data grid with a scrollbar and no pager. The underlying DomainDataSource should load only the data that is diplayed in the grid. It should trigger another load, when the user scrolls down to items that are not yet in the data context. Is there any sample implementation how to do this?

Marc Wittke
  • 2,991
  • 2
  • 30
  • 45
  • Update: Since the topic comes back I'm currently investigating 3rd-party controls. The Infragistics "VirtualCollection" seems to handle this the best way and can be bound to DomainServices - nice stuff – Marc Wittke Apr 18 '11 at 11:22

3 Answers3

1

I've just published a couple of blog posts (Part 1, Part 2) that give my solution to this problem. I have also posted a sample to GitHub that implements my own take on the VirtualCollection concept (I don't know how this compares with Infragistics's control, because I haven't used that).

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

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 a VirtualCollectionSource. Here's what the two key methods of NetflixTitlesSource look like:

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
    }
}
Samuel Jack
  • 32,712
  • 16
  • 118
  • 155
  • Looks promising. I'll definitly check it out. In the meantime we seriously tweaked the sources from infragistics to achive this... – Marc Wittke Aug 30 '12 at 06:40
1

Check out the work that Bea Stollnitz has done on her blog. Although not a direct answer to your question, she has written quite a bit on UI and data visualization. Here are a link from her blog that I think might help to get you started:

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

HTH!
Chris

Chris Koenig
  • 2,736
  • 18
  • 17
  • Thank you Chris, I finally read it yesterday. You're absolutely right, it is no direct answer but contains some nice proposals. – Marc Wittke Jun 08 '10 at 06:07
  • 1
    That link is broken, but I think this is the same content from Bea: http://www.zagstudio.com/blog/498#.UE8TT42PXQs – iggymoran Sep 11 '12 at 10:33
1

It's called stealth paging. Component One has a sample of their DataGrid that uses Stealth Paging. As soon as you scroll down, it gets the next page.

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

Shows the demo, and you can download the sample which show the code.

Hope this helps,

Greg

Greg Gum
  • 33,478
  • 39
  • 162
  • 233