使用全新发布的RIA服务中的业务应用程序模板,您可以在一个顶部使用数据网格看到很多示例 DomainDataSource 结合一个 DataPager. 。属性可以使用PageSize和LoadSize来调整一个页面中要显示的数据量以及在后台预取的数据。

现在,我想拥有一个带有滚动条的数据网格,没有寻呼机。基础 DomainDataSource 应仅加载网格中文字的数据。当用户向下滚动到数据上下文中尚未的项目时,它应该触发另一个负载。是否有任何样本实现如何执行此操作?

有帮助吗?

解决方案

我刚刚发表了几篇博客文章(第1部分, 第2部分)为我解决这个问题。我也发布了 一个样品 github来实现我自己对虚拟票据概念的看法(我不知道这与Infragistics的控制如何比较,因为我没有使用过)。

为了显示使用的容易,以下是样本中的一些片段。首先,这是您的使用方式 虚拟收获, ,协调获取数据的类:

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();
    }
}

在XAML中,您只需绑定 Items 属性到 ItemsSource 属性 ListBox 或者 DataGrid

对于每个数据源,您必须实现VirtualCollectionsource。这是两个关键方法 Netflixtitlessource 看起来像:

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
    }
}

其他提示

查看Bea Stollnitz在她的博客上所做的工作。尽管不是您问题的直接答案,但她已经写了很多关于UI和数据可视化的文章。以下是她的博客中的链接,我认为这可能会帮助您入门:

数据虚拟化: http://bea.stollnitz.com/blog/?p=344

恩!
克里斯

这就是所谓的隐形寻求。组件One具有使用隐形分页的数据级示例。向下滚动后,它将获得下一页。

http://demo.componentone.com/silverlight/controlexplorer/#datagrid/stealth%20paging

显示演示,您可以下载显示代码的示例。

希望这可以帮助,

格雷格

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top