有没有应用RIA Services SP1的DomainCollectionView的MVVM示例?

xhtmldivcss 2011-05-09 01:55:31
What is the DomainCollectionView?

The DomainCollectionView (herein referred to as the DCV) is a collection view implementation. The generic version of the class implements all the following interfaces. Most controls are designed to recognize and work against these interfaces.

ICollectionView
IEditableCollectionView
IPagedCollectionView
IEnumerable
IEnumerable<T>
INotifyPropertyChanged
INotifyCollectionChanged

……
...全文
98 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
xhtmldivcss 2011-07-25
  • 打赏
  • 举报
回复

public class ProductsViewModel
{
private NorthwindDomainContext _Context = new NorthwindDomainContext();

private EntityList<Product> _source;
private DomainCollectionViewLoader _loader;
private DomainCollectionView _view;

public ProductsViewModel()
{
_source = new EntityList<Product>(_Context.Products);
_loader = new DomainCollectionViewLoader<Product>(LoadProducts, OnLoadProductsCompleted);
_view = new DomainCollectionView(_loader, _source);

INotifyCollectionChanged notifySortDescriptions = (INotifyCollectionChanged)CollectionView.SortDescriptions;
notifySortDescriptions.CollectionChanged += (s, e) => this._view.MoveToFirstPage();

if (!DesignerProperties.IsInDesignTool)
{
using (this.CollectionView.DeferRefresh())
{
this._view.PageSize = 15;
this._view.MoveToFirstPage();
}
}

}
// ProductEntitySet只用于测试
public EntitySet<Product> ProductEntitySet
{
get { return this._Context.Products; }
}

public ICollectionView CollectionView
{
get
{
return this._view;
}
}
LoadOperation<Product> LoadProducts()
{
var query = _Context.GetProductsQuery();
return _Context.Load(query.SortAndPageBy(this._view));
}
void OnLoadProductsCompleted(LoadOperation<Product> lo)
{
if (lo.HasError)
{
lo.MarkErrorAsHandled();
MessageBox.Show(lo.Error.Message);
}
else if (!lo.IsCanceled)
{
this._source.Source = lo.Entities;

if (lo.TotalEntityCount != -1)
{
this._view.SetTotalItemCount(lo.TotalEntityCount);
}

}
}

}


<sdk:DataGrid  ItemsSource="{Binding CollectionView}" Margin="12,12,0,0" Name="productDataGrid" ……>
<sdk:DataPager Source="{Binding CollectionView}" Name="dataPager1" PageSize="10" />


另外一个DataGrid绑定到EntitySet<Product>,翻页的过程中可以看出因为EntityList<Product>的因故,虽然看起来Silverlight只显示当前页,实际上DomainContext一直在累加数据。
jv9 2011-05-09
  • 打赏
  • 举报
回复
这里有一套中文的教程可以参考:

http://www.silverlightchina.net/html/tips/2011/0503/7343.html
http://www.silverlightchina.net/html/tips/2011/0504/7360.html
http://www.silverlightchina.net/html/tips/2011/0504/7362.html
http://www.silverlightchina.net/html/tips/2011/0504/7363.html
http://www.silverlightchina.net/html/tips/2011/0504/7396.html
http://www.silverlightchina.net/html/tips/2011/0505/7405.html


8,734

社区成员

发帖
与我相关
我的任务
社区描述
WPF/Silverlight相关讨论
社区管理员
  • WPF/Silverlight社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧