我有一个包含两个定义的CollectionViews的视图模型。
一个是我用来导航和数据输入/编辑的。另一个我想用来过滤的,并在表单的列表视图中显示过滤。
我不希望在对可观察的集合应用筛选时,主视图(用于DataEntry目的)受到影响。
提前感谢!
发布于 2011-07-14 17:47:34
只要您使用单独的集合视图,更改其中一个不会影响另一个。这就是集合视图的意义--它们是同一集合上的独立视图。
发布于 2011-07-15 14:23:15
好了,明白了!并带着同样的想法继续前行。但是当我这样做的时候,我得到了错误=“调用线程无法访问这个对象,因为另一个线程拥有它。”因此我的过滤不起作用..以下是代码-
public ICollectionView Clients { get; set; } //Used for Data-navigation/modification
public ListCollectionView CodeView { get; set; } // to be used for filteration purpose on form.
string searchText = String.Empty;
public string CompanyCodeSearch
{
get { return searchText; }
set
{
try
{
searchText = value;
OnPropertyChanged("CompanyCodeSearch");
CodeView.Filter = new Predicate<object>(cmFilterData);
}
catch (Exception ex)
{
}
}
}
private bool cmFilterData(object item)
{
bool _filteredData = false;
try
{
var value = (item as cntClient);
if (value == null || value.CompanyCode == null)
return false;
_filteredData = value.CompanyCode.StartsWith(this.CompanyCodeSearch);
return _filteredData;
}
catch (Exception ex)
{
return false;
}
}
https://stackoverflow.com/questions/6697343
复制相似问题