I have an observable collection of objects. I wish to bind a gridview to this observable collection. But there is a constraint that only objects whose property x has value a, must be binded
How to do that?
I got it working using CollectionView and filter. For others benefit the code is as follows
Solution :
public class CustomerViewModel
{
public ObservableCollection<Customer> Customers
{
get;
set;
}
private ICollectionView _filteredCustomerView;
public ICollectionView FilteredCustomers
{
get { return _filteredCustomerView; }
}
public CustomerViewModel()
{
this.Customers= new ObservableCollection<Customer>();
Customers= GetCustomer();
_filteredCustomerView= CollectionViewSource.GetDefaultView(Customers);
_filteredCustomerView.Filter = MyCustomFilter;
}
private bool MyCustomFilter(object item)
{
Customer cust = item as Customer;
return (cust.Location == "someValue");
}
}