捕获在视图模型
答
不熟悉MVVM轻,但是我敢肯定你所谈论的是标准的WPF框架位。
的Filter
财产上的ICollectionView
是Predicate<object
>,你可以设置为你的视图模型一个给定的方法,将各Filter
需要行使时调用。实现这一
一种方式是通过定义ICollectionView
作为被绑定到你的视图中的视图模型中的属性。
private ICollectionView _view;
public ICollectionView Data
{
get
{
if (_view == null)
{
_view = CollectionViewSource.GetDefaultView(someCollection);
_view.Filter = Filter;
}
return _view;
}
}
private bool Filter(object arg)
{
//arg is the object being filtered on to make the decision of
//it being included in the returned ICollectionView
return true;
}
这允许所有逻辑保留在ViewModel中,我相信这是您的最终目标。
答
您可能会对将CollectionViewSource的Filter委托给ViewModel的示例应用程序感兴趣。但是,它不使用MVVM Light。将样品的WPF Application Framework (WAF)一部分。