PagedCollectionView.Filter Property

Silverlight

Gets or sets a callback that is used to determine whether an item is suited for inclusion in the view.

Namespace:  System.Windows.Data
Assembly:  System.Windows.Data (in System.Windows.Data.dll)

public Predicate<Object> Filter { get; set; }

Property Value

Type: System.Predicate<Object>
A method that is used to determine whether an item is suited for inclusion in the view.

Implements

ICollectionView.Filter

ExceptionCondition
NotSupportedException

The implementation does not support filtering.

Simpler implementations do not support filtering and will throw a NotSupportedException. Check the CanFilter property to test whether filtering is supported before assigning a non-null value.

InvalidOperationException

IsAddingNew is true.

-or-

IsEditingItem is true.

The Filter is a callback set by the consumer of the ICollectionView and used by the implementation of the ICollectionView to determine whether an item is suited for inclusion in the view.

The following code example demonstrates how to use the Filter property to remove completed tasks from a DataGrid display. The filter is applied when a CheckBox is Checked, and removed when the CheckBox is Unchecked. This example is part of a larger example available in the How to: Group, Sort, and Filter Data in the DataGrid Control topic.


private void CheckBox_Checked(object sender, RoutedEventArgs e)
{
    PagedCollectionView pcv = this.dataGrid1.ItemsSource as PagedCollectionView;
    if (pcv != null && pcv.CanFilter == true)
    {
        // Apply the filter.
        pcv.Filter = new Predicate<object>(FilterCompletedTasks);
    }
}

private void CheckBox_Unchecked(object sender, RoutedEventArgs e)
{
    PagedCollectionView pcv = this.dataGrid1.ItemsSource as PagedCollectionView;
    if (pcv != null)
    {
        // Remove the filter.
        pcv.Filter = null;
    }
}

public bool FilterCompletedTasks(object t)
{
    Task task = t as Task;
    return (task.Complete == false);
}


Silverlight

Supported in: 5, 4, 3

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions

ADD
Show: