WPF DataGrid filtering for Caliburn.Micro

caliburn.micro, datagrid, filtering, wpf

Solution

Create a new property in the view-model:

private ICollectionView fooView;

public ICollectionView FooView
{
    get
    {
        return this.fooView;
    }

    set
    {
        this.fooView = value;

        NotifyPropertyChanged("FooView");
    }
}

And then after you populate the bindable collection:

// Populate collection
BindableCollection collectionName = this.PopulateCollection();

FooView = CollectionViewSource.GetDefaultView(collectionName);

In your view change the binding from `collectionName` to `FooView`.

The CollectionView classes provide ways to sort/filter/group the data. In your case How to: Filter Data in a View. The filter code will vary depending on your model and requirements.

Problem

I have a WPF application using Caliburn.Micro. A DataGrid is bound to a collection of objects in the ViewModel. Could you please suggest a way to filter the DataGrid contents, if possible by any field? Thanks.

Original source