简体   繁体   English

在Silverlight 4中创建MVVM DataPager的好方法是什么?

[英]What is the good way to create MVVM DataPager in Silverlight 4?

I want to use DataPager with MVVM but it's not easy. 我想将DataPager与MVVM一起使用,但这并不容易。 After I search on internet, there are 2 ways to use DataPager with MVVM in Silverlight. 在Internet上搜索之后,有两种方法可以在Silverlight中将DataPager与MVVM结合使用。

  1. Introducing An MVVM-Friendly DomainDataSource: The DomainCollectionView ( update post for Mix 11) 引入对MVVM友好的DomainDataSource:DomainCollectionView (Mix 11的更新发布
  2. Architecting Silverlight LOB applications (Part 6) – Building an MVVM Framework 架构Silverlight LOB应用程序(第6部分)–构建MVVM框架

Now I use method #1 but there are some problems with it, for example, i don't know when user change DataPager's page then I can't set BusyIndicator IsBusy to true. 现在,我使用方法#1,但是存在一些问题,例如,我不知道用户何时更改DataPager的页面,然后无法将BusyIndi​​cator IsBusy设置为true。

I want to know, what is a good way to use MVVM with DataPager? 我想知道,将MVVM与DataPager一起使用的好方法是什么?

The DomainCollectionView, as you mention at #1, is the way I've found. 正如您在第一点提到的,DomainCollectionView是我找到的方法。

The DataPager is bound to your DomainCollectionView, so all the user's commands on the pager are passed on. DataPager绑定到您的DomainCollectionView,因此在传呼器上的所有用户命令都将传递。 This is being done thru the interfaces that the DomainCollectionView implements, notably IPagedCollectionView, which the DataPager knows how to handle. 这是通过DomainCollectionView实现的接口来完成的,特别是IPagedCollectionView,DataPager知道如何处理这些接口。

Whenever the DataPager needs a new page, it will update the DomainCollectionView, which will in turn call your load function which is setup on the DomainCollectionViewLoader. 每当DataPager需要新页面时,它将更新DomainCollectionView,后者将依次调用在DomainCollectionViewLoader上设置的加载函数。 The article you link gives examples of getting this all set up. 您链接的文章提供了完成所有步骤的示例。

Some place in the setup of the DomainCollectionView, you will create your DomainCollectionViewLoader something like this: 在DomainCollectionView的安装程序中的某个位置,您将创建类似于以下内容的DomainCollectionViewLoader:

... = new DomainCollectionViewLoader<Customer>(LoadCustomers, OnLoadCustomersCompleted);

In your function LoadCustomers(), you can start showing the BusyIndicator, and when OnLoadCusomtersCompleted() gets hit, you can stop it. 在函数LoadCustomers()中,您可以开始显示BusyIndi​​cator,当OnLoadCusomtersCompleted()被点击时,您可以停止它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM