I've got a combobox that is bound to a List<Person>
(ItemsSource is set in CodeBehind).
<ComboBox Width="120" Background="White" DisplayMemberPath="Name" />
So the names of all persons are added to the List.
Because it's not necessary to show every name in the ComboBox, I added a property Hide
of type bool
. If this property is set to true, the name should not be shown in the combobox.
But how is it possible to add a condition to the Binding of the combobox, so that only those persons are listed who are not supposed to be hidden.
EDIT: Regarding answers, I added the following code:
{
List<Person> persons;
...
var collectionView = CollectionViewSource.GetDefaultView(persons);
collectionView.Filter = HideFilter;
}
...
private bool HideFilter(object item)
{
Person p = item as Person;
return p.Hide;
}
But this throws a TargetInvocationException on collectionView.Filter = HideFilter;
.
What did I misunderstand?