Share via


PagedCollectionView.CanFilter Property

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Gets a value that indicates whether this view supports filtering by way of the Filter property.

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

Syntax

'Declaration
Public ReadOnly Property CanFilter As Boolean
public bool CanFilter { get; }

Property Value

Type: System.Boolean
true in all cases.

Implements

ICollectionView.CanFilter

Remarks

This implementation always returns true.

Typically, you use this property to test whether the view supports filtering before setting the Filter property.

Examples

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
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);
}

Version Information

Silverlight

Supported in: 5, 4, 3

Platforms

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