This topic has not yet been rated - Rate this topic

CollectionView.Filter Property

Gets or sets a method used to determine if an item is suitable for inclusion in the view.

Namespace:  System.Windows.Data
Assembly:  PresentationFramework (in PresentationFramework.dll)
abstract Filter : Predicate<Object> with get, set 
override Filter : Predicate<Object> with get, set

Property Value

Type: System.Predicate(Object)
A delegate that represents the method used to determine if an item is suitable for inclusion in the view.

Implements

ICollectionView.Filter
ExceptionCondition
NotSupportedException

The current implementation does not support filtering.

Simpler implementations do not support filtering and throw a NotSupportedException. Use the CanFilter property to test if filtering is supported before assigning this property with a non-null value.

This example shows how to filter data in a view.

To create a filter, define a method that provides the filtering logic. The method is used as a callback and accepts a parameter of type object. The following method returns all the Order objects with the filled property set to "No", filtering out the rest of the objects.

No code example is currently available or this language may not be supported.

You can then apply the filter, as shown in the following example. In this example, myCollectionView is a ListCollectionView object.

No code example is currently available or this language may not be supported.

To undo filtering, you can set the Filter property to a null reference (Nothing in Visual Basic):

No code example is currently available or this language may not be supported.

For information about how to create or obtain a view, see How to: Get the Default View of a Data Collection. For the complete example, see Sorting and Filtering Items in a View Sample.

If your view object comes from a CollectionViewSource object, you apply filtering logic by setting an event handler for the Filter event. In the following example, listingDataView is an instance of CollectionViewSource.

No code example is currently available or this language may not be supported.

The following shows the implementation of the example ShowOnlyBargainsFilter filter event handler. This event handler uses the Accepted property to filter out AuctionItem objects that have a CurrentPrice of $25 or greater.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Did you find this helpful?
(1500 characters remaining)
© 2013 Microsoft. All rights reserved.