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)

'Declaration
Public Property Filter As Predicate(Of Object)

Property Value

Type: System.Predicate(Of 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 Sub CheckBox_Checked(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
    Dim pcv As PagedCollectionView = Me.dataGrid1.ItemsSource
    If pcv IsNot Nothing & pcv.CanFilter = True Then
        ' Apply the filter.
        pcv.Filter = New Predicate(Of Object)(AddressOf FilterCompletedTasks)
    End If
End Sub

Private Sub CheckBox_Unchecked(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
    Dim pcv As PagedCollectionView = Me.dataGrid1.ItemsSource
    If pcv IsNot Nothing Then
        ' Remove the filter.
        pcv.Filter = Nothing
    End If
End Sub

Public Function FilterCompletedTasks(ByVal t As Object) As Boolean
    Dim _task As New Task
    _task = t
    Return _task.Complete = False
End Function


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: