如何在不使用分页的情况下实现延迟加载的 Silverlight 数据网格 [英] How to implement a lazy loaded Silverlight data grid without using paging

查看:13
本文介绍了如何在不使用分页的情况下实现延迟加载的 Silverlight 数据网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

现在我想要一个带有滚动条但没有分页器的数据网格.底层 DomainDataSource 应该只加载在网格中显示的数据.当用户向下滚动到尚未出现在数据上下文中的项目时,它应该触发另一个加载.是否有任何示例实现如何执行此操作?

解决方案

我刚刚发表了几篇博文 (第 1 部分第 2 部分)给出了我对这个问题的解决方案.我还向 GitHub 发布了一个示例,该示例实现了我自己对 VirtualCollection 概念的看法(我不知道这与 Infragistics 的控制相比如何,因为我没有使用过).

为了展示它的易用性,以下是示例中的一些片段.首先,这是您如何使用 VirtualCollection 的类坐标获取数据:

公共类 MainViewModel : ViewModel{私人 NetflixTitlesSource _source;public VirtualCollection项目{得到;私人订制;}公共主视图模型(){_source = 新的 NetflixTitlesSource();Items = new VirtualCollection<Title>(_source, pageSize: 20, cachedPages: 5);}受保护的覆盖 void OnViewLoaded(){Items.Refresh();}}</code></pre><p>在 XAML 中,您只需将 <code>Items</code> 属性绑定到 <code>ListBox</code> 或 <code>DataGrid</code> 的 <code>ItemsSource</code> 属性><p>对于每个数据源,您必须实现一个 VirtualCollectionSource.下面是 <a href="https://github.com/samueldjack/VirtualCollection/blob/master/VirtualCollection/Demo/NetflixTitlesSource.cs" rel="nofollow">NetflixTitlesSource</a> 的两个关键方法:</p><pre><code>公共类 NetflixTitlesSource : VirtualCollectionSource<Title>{受保护的覆盖任务<int>获取计数(){返回 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){返回 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){//查询 Netflix OData API 的代码}}</code></pre><p><p>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 <code>DomainDataSource</code> in combination with a <code>DataPager</code>. 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.</p>

<p>Now I'd like to have a data grid with a scrollbar and no pager. The underlying <code>DomainDataSource</code> 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?</p><div class="h2_lin"> 解决方案 </div><p>I've just published a couple of blog posts (<a href="http://blog.hibernatingrhinos.com/12513/data-virtualization-lazy-loading-stealth-pagingndash-whatever-you-want-to-call-it-herersquo-s-how-to-do-it-in-silverlight" rel="nofollow">Part 1</a>, <a href="http://blog.hibernatingrhinos.com/12514/data-virtualization-in-silverlight-digging-into-virtualcollection" rel="nofollow">Part 2</a>) that give my solution to this problem. I have also posted <a href="https://github.com/samueldjack/VirtualCollection" rel="nofollow">a sample</a> 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).</p>

<p>To show how easy it is to use, here are a few snippets from the sample. First, here's how you use <a href="https://github.com/samueldjack/VirtualCollection/blob/master/VirtualCollection/VirtualCollection/VirtualCollection.cs" rel="nofollow">VirtualCollection</a>, the class that coordinates fetching the data:</p><pre><code>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();
    }
}
</code></pre><p>In XAML you simply bind the <code>Items</code> property to the <code>ItemsSource</code> property of a <code>ListBox</code> or <code>DataGrid</code></p>

<p>For each data source you must implement a VirtualCollectionSource. Here's what the two key methods of <a href="https://github.com/samueldjack/VirtualCollection/blob/master/VirtualCollection/Demo/NetflixTitlesSource.cs" rel="nofollow">NetflixTitlesSource</a> look like:</p><pre><code>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
    }
}
</code></pre><p>

                        <p>这篇关于如何在不使用分页的情况下实现延迟加载的 Silverlight 数据网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!</p>
                        
                    </div>
                    <div class="arc-body-main-more">
                        <span onclick="unlockarc('2710072');">查看全文</span>
                    </div>
                </div>
				<div>
                            
                        </div>
                <div class="wwads-cn wwads-horizontal" data-id="166" style="max-width:100%;border: 4px solid #666;"></div>
            </div>
        </article>
        <div id="arc-ad-2" class="mb-1">
            <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5038752844014834"
     crossorigin="anonymous"></script>
<ins class="adsbygoogle"
     style="display:block"
     data-ad-format="autorelaxed"
     data-ad-client="ca-pub-5038752844014834"
     data-ad-slot="3921941283"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>

        </div>
        <div class="widget bgwhite radius-1 mb-1 shadow widget-rel">
            <h5>相关文章</h5>
            <ul>
                    <li>
                        <a target="_blank" title="如何在不使用分页的情况下实现延迟加载的Silverlight数据网格" href="/1863814.html">
                            如何在不使用分页的情况下实现延迟加载的Silverlight数据网格;
                        </a>
                    </li>
                    <li>
                        <a target="_blank" title="如何在不使用DefaultServeMux的情况下实现HandlerFunc" href="/810052.html">
                            如何在不使用DefaultServeMux的情况下实现HandlerFunc;
                        </a>
                    </li>
                    <li>
                        <a target="_blank" title="如何在不使用网格视图的情况下显示数据库数据?" href="/1116034.html">
                            如何在不使用网格视图的情况下显示数据库数据?;
                        </a>
                    </li>
                    <li>
                        <a target="_blank" title="如何在不使用cpu时间的情况下引入小延迟" href="/1067202.html">
                            如何在不使用cpu时间的情况下引入小延迟;
                        </a>
                    </li>
                    <li>
                        <a target="_blank" title="如何在不使用表格的情况下实现表格布局?" href="/2729942.html">
                            如何在不使用表格的情况下实现表格布局?;
                        </a>
                    </li>
                    <li>
                        <a target="_blank" title="如何在不使用 AppDomains 的情况下实现 .net 插件?" href="/2564619.html">
                            如何在不使用 AppDomains 的情况下实现 .net 插件?;
                        </a>
                    </li>
                    <li>
                        <a target="_blank" title="如何在不使用JOIN的情况下实现SQL连接?" href="/2151863.html">
                            如何在不使用JOIN的情况下实现SQL连接?;
                        </a>
                    </li>
                    <li>
                        <a target="_blank" title="如何在不使用索引的情况下搜索数据" href="/1416733.html">
                            如何在不使用索引的情况下搜索数据;
                        </a>
                    </li>
                    <li>
                        <a target="_blank" title="如何在不使用 ImageView 的情况下使用 Picasso 加载位图?" href="/2615884.html">
                            如何在不使用 ImageView 的情况下使用 Picasso 加载位图?;
                        </a>
                    </li>
                    <li>
                        <a target="_blank" title="实现IDataErrorInfo使用NHibernate的延迟加载情况下使用Castle.DynamicProxy" href="/30679.html">
                            实现IDataErrorInfo使用NHibernate的延迟加载情况下使用Castle.DynamicProxy;
                        </a>
                    </li>
                    <li>
                        <a target="_blank" title="如何在不使用数据库的情况下从数据网格中全局搜索数据。" href="/1127758.html">
                            如何在不使用数据库的情况下从数据网格中全局搜索数据。;
                        </a>
                    </li>
                    <li>
                        <a target="_blank" title="如何在不使用mvvm的情况下在Silverlight中实现货币管理?" href="/1238767.html">
                            如何在不使用mvvm的情况下在Silverlight中实现货币管理?;
                        </a>
                    </li>
                    <li>
                        <a target="_blank" title="“letrec"如何?在不使用“set!"的情况下实现?" href="/2396826.html">
                            “letrec"如何?在不使用“set!"的情况下实现?;
                        </a>
                    </li>
                    <li>
                        <a target="_blank" title="在不使用数据库的情况下填充网格视图" href="/1376935.html">
                            在不使用数据库的情况下填充网格视图;
                        </a>
                    </li>
                    <li>
                        <a target="_blank" title="如何在不使用addValueEventListener的情况下访问Firebase数据" href="/994278.html">
                            如何在不使用addValueEventListener的情况下访问Firebase数据;
                        </a>
                    </li>
                    <li>
                        <a target="_blank" title="RxJS - 如何在不使用间隔的情况下逐步增加延迟时间?" href="/2391217.html">
                            RxJS - 如何在不使用间隔的情况下逐步增加延迟时间?;
                        </a>
                    </li>
                    <li>
                        <a target="_blank" title="如何在不使用Android SDK的情况下不使用playUri的情况下获取歌曲元数据?" href="/1816724.html">
                            如何在不使用Android SDK的情况下不使用playUri的情况下获取歌曲元数据?;
                        </a>
                    </li>
                    <li>
                        <a target="_blank" title="如何在不使用thread.sleep的情况下延迟android中的循环?" href="/964450.html">
                            如何在不使用thread.sleep的情况下延迟android中的循环?;
                        </a>
                    </li>
                    <li>
                        <a target="_blank" title="在不使用隐藏网格的情况下导出Dataview" href="/1431626.html">
                            在不使用隐藏网格的情况下导出Dataview;
                        </a>
                    </li>
                    <li>
                        <a target="_blank" title="如何在不使用 abort() 的情况下 assert()?" href="/2621364.html">
                            如何在不使用 abort() 的情况下 assert()?;
                        </a>
                    </li>
                    <li>
                        <a target="_blank" title="在不使用 flex 的情况下加载 RSL?" href="/2545915.html">
                            在不使用 flex 的情况下加载 RSL?;
                        </a>
                    </li>
                    <li>
                        <a target="_blank" title="如何在不使用抽象的情况下强制实现子类中的方法?" href="/2604086.html">
                            如何在不使用抽象的情况下强制实现子类中的方法?;
                        </a>
                    </li>
                    <li>
                        <a target="_blank" title="如何在不使用抽象的情况下强制实现子类中的方法?" href="/2610932.html">
                            如何在不使用抽象的情况下强制实现子类中的方法?;
                        </a>
                    </li>
                    <li>
                        <a target="_blank" title="如何在不使用抽象的情况下强制实现子类中的方法?" href="/1622535.html">
                            如何在不使用抽象的情况下强制实现子类中的方法?;
                        </a>
                    </li>
                    <li>
                        <a target="_blank" title="如何在不向下滚动的情况下强制加载动态内容(使用延迟加载)" href="/1186608.html">
                            如何在不向下滚动的情况下强制加载动态内容(使用延迟加载);
                        </a>
                    </li>
            </ul>
        </div>
        <div class="mb-1">
            <script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-5038752844014834"
     crossorigin="anonymous"></script>
<ins class="adsbygoogle"
     style="display:block"
     data-ad-format="autorelaxed"
     data-ad-client="ca-pub-5038752844014834"
     data-ad-slot="3921941283"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>

        </div>
    </div>
    <div class="side">
        <div class="widget widget-side bgwhite mb-1 shadow">
            <h5>其他开发最新文章</h5>
            <ul>
                    <li>
                        <a target="_blank" title="拒绝显示一个框架,因为它将'X-Frame-Options'设置为'sameorigin'" href="/893060.html">
                            拒绝显示一个框架,因为它将'X-Frame-Options'设置为'sameorigin';
                        </a>
                    </li>
                    <li>
                        <a target="_blank" title="什么是&QUOT; AW&QUOT;在部分标志属性是什么意思?" href="/303988.html">
                            什么是&QUOT; AW&QUOT;在部分标志属性是什么意思?;
                        </a>
                    </li>
                    <li>
                        <a target="_blank" title="在运行npm install命令时获取'npm WARN弃用'警告" href="/840917.html">
                            在运行npm install命令时获取'npm WARN弃用'警告;
                        </a>
                    </li>
                    <li>
                        <a target="_blank" title="cmake无法找到openssl" href="/516280.html">
                            cmake无法找到openssl;
                        </a>
                    </li>
                    <li>
                        <a target="_blank" title="从Spark的scala中的* .tar.gz压缩文件中读取HDF5文件" href="/850628.html">
                            从Spark的scala中的* .tar.gz压缩文件中读取HDF5文件;
                        </a>
                    </li>
                    <li>
                        <a target="_blank" title="Twitter :: Error :: Forbidden  - 无法验证您的凭据" href="/630061.html">
                            Twitter :: Error :: Forbidden  - 无法验证您的凭据;
                        </a>
                    </li>
                    <li>
                        <a target="_blank" title="我什么时候需要一个fb:app_id或者fb:admins?" href="/747981.html">
                            我什么时候需要一个fb:app_id或者fb:admins?;
                        </a>
                    </li>
                    <li>
                        <a target="_blank" title="将.db文件导入R" href="/902960.html">
                            将.db文件导入R;
                        </a>
                    </li>
                    <li>
                        <a target="_blank" title="npm通知创建一个lockfile作为package-lock.json。你应该提交这个文件" href="/744854.html">
                            npm通知创建一个lockfile作为package-lock.json。你应该提交这个文件;
                        </a>
                    </li>
                    <li>
                        <a target="_blank" title="拒绝执行内联脚本,因为它违反了以下内容安全策略指令:“script-src'self'”" href="/819167.html">
                            拒绝执行内联脚本,因为它违反了以下内容安全策略指令:“script-src'self'”;
                        </a>
                    </li>
            </ul>
        </div>
        <div class="widget widget-side bgwhite mb-1 shadow">
            <h5>
                热门教程
            </h5>
            <ul>
                <li>
                    <a target="_blank" title="Java教程" href="/OnLineTutorial/java/index.html">
                        Java教程
                    </a>
                </li>
                <li>
                    <a target="_blank" title="Apache ANT 教程" href="/OnLineTutorial/ant/index.html">
                        Apache ANT 教程
                    </a>
                </li>
                <li>
                    <a target="_blank" title="Kali Linux教程" href="/OnLineTutorial/kali_linux/index.html">
                        Kali Linux教程
                    </a>
                </li>
                <li>
                    <a target="_blank" title="JavaScript教程" href="/OnLineTutorial/javascript/index.html">
                        JavaScript教程
                    </a>
                </li>
                <li>
                    <a target="_blank" title="JavaFx教程" href="/OnLineTutorial/javafx/index.html">
                        JavaFx教程
                    </a>
                </li>
                <li>
                    <a target="_blank" title="MFC 教程" href="/OnLineTutorial/mfc/index.html">
                        MFC 教程
                    </a>
                </li>
                <li>
                    <a target="_blank" title="Apache HTTP客户端教程" href="/OnLineTutorial/apache_httpclient/index.html">
                        Apache HTTP客户端教程
                    </a>
                </li>
                <li>
                    <a target="_blank" title="Microsoft Visio 教程" href="/OnLineTutorial/microsoft_visio/index.html">
                        Microsoft Visio 教程
                    </a>
                </li>
            </ul>
        </div>
        <div class="widget widget-side bgwhite mb-1 shadow">
            <h5>
                热门工具
            </h5>
            <ul>
                
                <li>
                    <a target="_blank" title="Java 在线工具" href="/Onlinetools/details/4">
                        Java 在线工具
                    </a>
                </li>
                <li>
                    <a target="_blank" title="C(GCC) 在线工具" href="/Onlinetools/details/6">
                        C(GCC) 在线工具
                    </a>
                </li>
                <li>
                    <a target="_blank" title="PHP 在线工具" href="/Onlinetools/details/8">
                        PHP 在线工具
                    </a>
                </li>
                <li>
                    <a target="_blank" title="C# 在线工具" href="/Onlinetools/details/1">
                        C# 在线工具
                    </a>
                </li>
                <li>
                    <a target="_blank" title="Python 在线工具" href="/Onlinetools/details/5">
                        Python 在线工具
                    </a>
                </li>
                <li>
                    <a target="_blank" title="MySQL 在线工具" href="/Onlinetools/Dbdetails/33">
                        MySQL 在线工具
                    </a>
                </li>
                <li>
                    <a target="_blank" title="VB.NET 在线工具" href="/Onlinetools/details/2">
                        VB.NET 在线工具
                    </a>
                </li>
                <li>
                    <a target="_blank" title="Lua 在线工具" href="/Onlinetools/details/14">
                        Lua 在线工具
                    </a>
                </li>
                <li>
                    <a target="_blank" title="Oracle 在线工具" href="/Onlinetools/Dbdetails/35">
                        Oracle 在线工具
                    </a>
                </li>
                <li>
                    <a target="_blank" title="C++(GCC) 在线工具" href="/Onlinetools/details/7">
                        C++(GCC) 在线工具
                    </a>
                </li>
                <li>
                    <a target="_blank" title="Go 在线工具" href="/Onlinetools/details/20">
                        Go 在线工具
                    </a>
                </li>
                <li>
                    <a target="_blank" title="Fortran 在线工具" href="/Onlinetools/details/45">
                        Fortran 在线工具
                    </a>
                </li>
            </ul>
        </div>
        
    </div>
</div>
<script type="text/javascript">var eskeys = '如,何在,不,使用,分页,的,情况下,实现,延迟,加载,的,silverlight,数据,网格'; var cat = 'cc';';//other-dev</script>
    </div>
<div id="pop" onclick="pophide();">
    <div id="pop_body" onclick="event.stopPropagation();">
        <h6 class="flex flex101">
            登录
            <span onclick="pophide();">关闭</span>
        </h6>
        <div class="pd-1">
            <div class="wxtip center">
                <span>扫码关注<em>1秒</em>登录</span>
            </div>
            <div class="center">
                <img id="qr" src="https://huajiakeji.com/Content/Images/qrydx.jpg" alt="" style="width:150px;height:150px;" />
            </div>
            <div style="margin-top:10px;display:flex;justify-content: center;">
                <input type="text" placeholder="输入验证码" id="txtcode" autocomplete="off" />
                <input id="btngo" type="button" onclick="chk()" value="GO" />
            </div>
            <div class="center" style="margin: 4px; font-size: .8rem; color: #f60;">
                发送“验证码”获取
                <em style="padding: 0 .5rem;">|</em>
                <span style="color: #01a05c;">15天全站免登陆</span>
            </div>
            <div id="chkinfo" class="tip"></div>
        </div>
    </div>
</div>    <script type="text/javascript" src="https://lib.sinaapp.com/js/jquery/1.9.1/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="https://cdn.bootcss.com/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
<script type="text/javascript" src="https://img01.yuandaxia.cn/Scripts/highlight.min.js"></script>
<script type="text/javascript" src="https://img01.yuandaxia.cn/Scripts/base.js?v=0.22"></script>
<script type="text/javascript" src="https://img01.yuandaxia.cn/Scripts/tui.js?v=0.11"></script>
<footer class="footer">
    <div class="container">
		<div class="flink mb-1">
			友情链接:
            <a href="https://www.it1352.com/" target="_blank">IT屋</a>
            <a href="https://huajiakeji.com/" target="_blank">Chrome插件</a>
            <a href="https://www.cnplugins.com/" target="_blank">谷歌浏览器插件</a>
        </div>
        <section class="copyright-section">
            <a href="https://www.it1352.com" title="IT屋-程序员软件开发技术分享社区">IT屋</a>
            ©2016-2022 <a href="http://www.beian.miit.gov.cn/" target="_blank">琼ICP备2021000895号-1</a>
            <a href="/sitemap.html" target="_blank" title="站点地图">站点地图</a>
            <a href="/Home/Tags" target="_blank" title="站点标签">站点标签</a>
            <a target="_blank" alt="sitemap" href="/sitemap.xml">SiteMap</a>
            <a href="/1155981.html" title="IT屋-免责申明"><免责申明></a>
            本站内容来源互联网,如果侵犯您的权益请联系我们删除.
        </section>
        
<!--统计代码-->
<script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?0c3a090f7b3c4ad458ac1296cb5cc779";
      var s = document.getElementsByTagName("script")[0]; 
      s.parentNode.insertBefore(hm, s);
    })();
</script>
<script type="text/javascript">
    (function () {
        var bp = document.createElement('script');
        var curProtocol = window.location.protocol.split(':')[0];
        if (curProtocol === 'https') {
            bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
        }
        else {
            bp.src = 'http://push.zhanzhang.baidu.com/push.js';
        }
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(bp, s);
    })();
</script>
    </div>
</footer>
</body>
</html>