HitTestFilterCallback Delegat

Definicja

Reprezentuje metodę wywołania zwrotnego, która określa części drzewa wizualnego do pominięcia z przetwarzania testów trafień.

public delegate System::Windows::Media::HitTestFilterBehavior HitTestFilterCallback(DependencyObject ^ potentialHitTestTarget);
public delegate System.Windows.Media.HitTestFilterBehavior HitTestFilterCallback(DependencyObject potentialHitTestTarget);
type HitTestFilterCallback = delegate of DependencyObject -> HitTestFilterBehavior
Public Delegate Function HitTestFilterCallback(potentialHitTestTarget As DependencyObject) As HitTestFilterBehavior 

Parametry

potentialHitTestTarget
DependencyObject

Wizualizacja do przetestowania.

Wartość zwracana

HitTestFilterBehavior

Element HitTestFilterBehavior reprezentujący akcję wynikową testu trafienia.

Przykłady

W poniższym przykładzie pokazano, jak wywołać HitTest metodę HitTestFilterCallback przy użyciu wartości. Zdefiniowano również odpowiednią metodę wywołania zwrotnego testu trafienia.

// Respond to the mouse wheel event by setting up a hit test filter and results enumeration.
private void OnMouseWheel(object sender, MouseWheelEventArgs e)
{
    // Retrieve the coordinate of the mouse position.
    Point pt = e.GetPosition((UIElement)sender);

    // Clear the contents of the list used for hit test results.
    hitResultsList.Clear();

    // Set up a callback to receive the hit test result enumeration.
    VisualTreeHelper.HitTest(myCanvas,
                      new HitTestFilterCallback(MyHitTestFilter),
                      new HitTestResultCallback(MyHitTestResult),
                      new PointHitTestParameters(pt));

    // Perform actions on the hit test results list.
    if (hitResultsList.Count > 0)
    {
        ProcessHitTestResultsList();
    }
}
' Respond to the mouse wheel event by setting up a hit test filter and results enumeration.
Private Overloads Sub OnMouseWheel(ByVal sender As Object, ByVal e As MouseWheelEventArgs)
    ' Retrieve the coordinate of the mouse position.
    Dim pt As Point = e.GetPosition(CType(sender, UIElement))

    ' Clear the contents of the list used for hit test results.
    hitResultsList.Clear()

    ' Set up a callback to receive the hit test result enumeration.
    VisualTreeHelper.HitTest(myCanvas, New HitTestFilterCallback(AddressOf MyHitTestFilter), New HitTestResultCallback(AddressOf MyHitTestResult), New PointHitTestParameters(pt))

    ' Perform actions on the hit test results list.
    If hitResultsList.Count > 0 Then
        ProcessHitTestResultsList()
    End If
End Sub

W poniższym przykładzie pokazano, jak zwrócić HitTestFilterBehavior wartość z metody wywołania zwrotnego filtru testu trafienia.

// Filter the hit test values for each object in the enumeration.
public HitTestFilterBehavior MyHitTestFilter(DependencyObject o)
{
    // Test for the object value you want to filter.
    if (o.GetType() == typeof(Label))
    {
        // Visual object and descendants are NOT part of hit test results enumeration.
        return HitTestFilterBehavior.ContinueSkipSelfAndChildren;
    }
    else
    {
        // Visual object is part of hit test results enumeration.
        return HitTestFilterBehavior.Continue;
    }
}
' Filter the hit test values for each object in the enumeration.
Public Function MyHitTestFilter(ByVal o As DependencyObject) As HitTestFilterBehavior
    ' Test for the object value you want to filter.
    If o.GetType() Is GetType(Label) Then
        ' Visual object and descendants are NOT part of hit test results enumeration.
        Return HitTestFilterBehavior.ContinueSkipSelfAndChildren
    Else
        ' Visual object is part of hit test results enumeration.
        Return HitTestFilterBehavior.Continue
    End If
End Function

Uwagi

Metoda wywołania zwrotnego filtru testów trafień jest wywoływana dla wszystkich obiektów wizualnych mapujących na kryteria testu trafienia, począwszy od określonej wizualizacji i malejąco przez jej gałąź drzewa wizualnego. Można jednak zignorować niektóre gałęzie drzewa wizualnego, które nie są zainteresowane przetwarzaniem funkcji wywołania zwrotnego wyników testów trafień. Wartość zwracana przez funkcję wywołania zwrotnego filtru testu trafienia określa typ akcji, jaką ma podjąć wyliczanie obiektów wizualnych. Jeśli na przykład zwracasz wartość , ContinueSkipSelfAndChildrenmożesz usunąć bieżący obiekt wizualizacji i jego elementy podrzędne z wyliczenia wyników testu trafień. Oznacza to, że metoda wywołania zwrotnego wyników testu trafień nie będzie widzieć tych obiektów w wyliczenie.

Uwaga

Przycinanie drzewa wizualnego obiektów zmniejsza ilość przetwarzania podczas testu trafienia wynik wyliczenia.

Oczyszczanie drzewa wizualnego przy użyciu filtru testu trafienia
Oczyszczanie drzewa wizualnego

Metody rozszerzania

GetMethodInfo(Delegate)

Pobiera obiekt reprezentujący metodę reprezentowaną przez określonego delegata.

Dotyczy

Zobacz też