这是一个想法,如果您需要过滤为什么不绑定到 ListCollectionView
in the View
ComboBox ItemsSource="{Binding PersonsView}" //instead of Persons
在您的视图模型中:
public ListCollectionView PersonsView
{
get { return _personsView; }
private set
{
_personsView= value;
_personsView.CommitNew();
RaisePropertyChanged(()=>PersonsView);
}
}
一旦你填充你的列表
PersonsView= new ListCollectionView(_persons);
在您看来,您显然有一个地方可以响应组合框的更改,您可以在其中更新过滤器,您可以将应用过滤器放在那里
_viewModel.PersonsView.Filter = ApplyFilter;
其中 ApplyFilter 是决定显示内容的操作
//this will evaluate all items in the collection
private bool ApplyFilter(object item)
{
var person = item as Person;
if(person == null)
{
if(person is in that 30 top percent records)
return false; //don't filter them out
}
return true;
}
//or you can do some other logic to test that Condition that decides which Person is displayed, this is obviously a rough sample
}