在 Silverlight 中将 RIA 服务集合公开为可分页的 ViewModel 列表的最佳/最简单方法是什么?
在 Silverlight 4(或更高版本)中,我想要一个视图模型,该视图模型公开可分页的视图模型列表,这些视图模型派生自从 RIA 服务延迟检索的可分页实体列表。
例如,这里可能是代码隐藏/视图模型:
// Entities: Thousands exist, so they will be loaded lazily using the DataGrid's paging features.
private EntitySet<ExampleEntity> Entities { get; set; }
// View models: This list is a view of the Entities list.
public IList<ExampleEntityViewModel> EntityViewModels {
get {
return CreateDerivedCollection(this.Entities, this.CreateViewModel);
}
}
// This method will be called whenever Entities has a new item added.
public ExampleEntityViewModel CreateViewModel(ExampleEntity entity) {
return new ExampleEntityViewModel(entity);
}
这里可能是一些 Silverlight 4 XAML:
<sdk:DataGrid ItemsSource="{Binding Path=EntityViewModels}" />
<sdk:DataForm ItemsSource="{Binding Path=EntityViewModels}" />
如果我不关心分页,我会使用名为 Obtics 创建属性。 Obtics 很好,因为 Obtics 创建的列表是“反应式”的,这意味着当底层实体列表发生更改时,视图模型列表将根据我用来创建视图模型的表达式,通过监视属性更改和集合更改事件自动反映更改列表。
然而,我不相信(我可能是错的)这个 Obtics 列表能够与 Silverlight DataGrid/DataForm/等一起正常工作。控件,因为它不像可分页集合。
所以我的问题是:实现这一目标的最佳方法是什么?
我查看了一堆视图模型库(Prism、SimpleMVVM、Caliburn.Micro 和 RIAServices.ViewModel),但它们似乎都不支持这种情况。
In Silverlight 4 (or higher), I want to have a view model that exposes a pageable list of view models that are derived from a pageable list of entities that are lazily retrieved from RIA services.
For example here could be a code behind/view model:
// Entities: Thousands exist, so they will be loaded lazily using the DataGrid's paging features.
private EntitySet<ExampleEntity> Entities { get; set; }
// View models: This list is a view of the Entities list.
public IList<ExampleEntityViewModel> EntityViewModels {
get {
return CreateDerivedCollection(this.Entities, this.CreateViewModel);
}
}
// This method will be called whenever Entities has a new item added.
public ExampleEntityViewModel CreateViewModel(ExampleEntity entity) {
return new ExampleEntityViewModel(entity);
}
and here could be some Silverlight 4 XAML:
<sdk:DataGrid ItemsSource="{Binding Path=EntityViewModels}" />
<sdk:DataForm ItemsSource="{Binding Path=EntityViewModels}" />
If I weren't concerned about paging, I'd use library called Obtics to create the property. Obtics is nice because the list that Obtics creates is "Reactive", meaning when the underlying entity list changes, the view model list will automatically reflect the changes by monitory property change and collection change events based on an expression I use to create the view model list.
However, I don't believe (and I could be wrong) that this Obtics list will work right with the Silverlight DataGrid/DataForm/etc. controls because it doesn't act like a pageable collection.
So my question is: what is the best way to accomplish this?
I've looked at a bunch of view model libraries (Prism, SimpleMVVM, Caliburn.Micro, and RIAServices.ViewModel), and none of them seem to support this scenario.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 RIA Services Toolkit 的 DomainCollectionView 类。
请参阅http://blogs.msdn.com/b/kylemc/archive/2010/12/02/introducing-an-mvvm-friend-domaindatasource-the-domaincollectionview.aspx
You can use the class DomainCollectionView of RIA Services Toolkit.
See http://blogs.msdn.com/b/kylemc/archive/2010/12/02/introducing-an-mvvm-friendly-domaindatasource-the-domaincollectionview.aspx