在我查看我有一个AutoSuggestBox(searchfield)和ListView,我的ListView的的ItemSource为界,我的VM类属性:如何过滤列表属性
private Class1 _searchMatches;
public Class1 SearchMatches {
get { return _searchMatches; }
set { this.Set(ref _searchMatches, value); }
}
在我的Class1我有一个LoadItems任务:
异步任务> LoadItems()
var stocks = _response.products?
.Select(s => new MyClass(PLService.DtoToModel(s)))
.ToList();
var items = stocks.GroupBy(p => p.productModel.Description)
.Select(p => p.First())
.ToList();
return items;
当我在AutoSuggestBox键入测试并回车,什么是筛选项目,其中最简单的方法(item.description == searchterm)? 只是过滤它并更新itemsource,而不是重写属性
为什么不能在过滤器的过滤器的数据源,并应用其结果作为ListView的数据源? –
你能提供代码吗? – NicoTing
如果股票是一个ObservableCollection,那么你需要将它复制到一个临时变量清除原始集合,然后将过滤后的项目重新添加到源observable集合中。 –