CollectionViewSource.Filter 事件

定義

提供篩選邏輯。

public:
 event System::Windows::Data::FilterEventHandler ^ Filter;
public event System.Windows.Data.FilterEventHandler Filter;
member this.Filter : System.Windows.Data.FilterEventHandler 
Public Custom Event Filter As FilterEventHandler 

事件類型

範例

下列範例示範如何設定 事件的事件處理常式 Filter 。 在此範例中,listingDataViewCollectionViewSource 的執行個體。

listingDataView.Filter += new FilterEventHandler(ShowOnlyBargainsFilter);
AddHandler listingDataView.Filter, AddressOf ShowOnlyBargainsFilter

以下顯示範例 ShowOnlyBargainsFilter 篩選事件處理常式的實作。 這個事件處理常式會 Accepted 使用 屬性來篩選出 AuctionItem $ CurrentPrice 25 或更新版本為 $25 的物件。

private void ShowOnlyBargainsFilter(object sender, FilterEventArgs e)
{
    AuctionItem product = e.Item as AuctionItem;
    if (product != null)
    {
        // Filter out products with price 25 or above
        if (product.CurrentPrice < 25)
        {
            e.Accepted = true;
        }
        else
        {
            e.Accepted = false;
        }
    }
}
Private Sub ShowOnlyBargainsFilter(ByVal sender As Object, ByVal e As FilterEventArgs)
    Dim product As AuctionItem = CType(e.Item, AuctionItem)
    If Not (product Is Nothing) Then
        'Filter out products with price 25 or above
        If product.CurrentPrice < 25 Then
            e.Accepted = True
        Else
            e.Accepted = False
        End If
    End If
End Sub

如需完整範例,請參閱 資料系結示範

備註

檢視可以將篩選套用至集合。 這表示雖然專案可能存在於集合中,但特定檢視的目的是只顯示完整集合的特定子集。

您可以使用這個事件來設定事件處理常式,以提供篩選邏輯。

適用於