VisualTreeHelper.HitTest Metodo

Definizione

Restituisce l'oggetto Visual in primo piano di un hit test.

Overload

HitTest(Visual, Point)

Restituisce l'oggetto Visual in primo piano di un hit test specificando Point.

HitTest(Visual3D, HitTestFilterCallback, HitTestResultCallback, HitTestParameters3D)

Avvia un hit test sull'oggetto Visual3D specificato, con metodi HitTestFilterCallback e HitTestResultCallback definiti dal chiamante.

HitTest(Visual, HitTestFilterCallback, HitTestResultCallback, HitTestParameters)

Avvia un hit test sull'oggetto Visual specificato, con metodi HitTestFilterCallback e HitTestResultCallback definiti dal chiamante.

Commenti

I metodi di overload che accettano HitTestResultCallback e HitTestFilterCallback come parametri forniscono funzionalità aggiuntive durante il test di hit:

  • Consente di partecipare al controllo dell'attraversamento dell'albero visivo durante i test di hit test.

  • Consente di recuperare tutti gli oggetti visivi sotto il punto o la geometria, non solo quello superiore.

HitTest(Visual, Point)

Restituisce l'oggetto Visual in primo piano di un hit test specificando Point.

public:
 static System::Windows::Media::HitTestResult ^ HitTest(System::Windows::Media::Visual ^ reference, System::Windows::Point point);
public static System.Windows.Media.HitTestResult HitTest (System.Windows.Media.Visual reference, System.Windows.Point point);
static member HitTest : System.Windows.Media.Visual * System.Windows.Point -> System.Windows.Media.HitTestResult
Public Shared Function HitTest (reference As Visual, point As Point) As HitTestResult

Parametri

reference
Visual

Visual per l'hit test.

point
Point

Valore del punto da usare per l'hit test.

Restituisce

HitTestResult

Risultato dell'hit test di Visual, restituito come tipo HitTestResult.

Esempio

Nell'esempio seguente viene illustrato come usare il metodo per eseguire il HitTest test degli oggetti all'interno di un Canvasoggetto .

// Respond to the left mouse button down event by initiating the hit test.
private void OnMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
    // Retrieve the coordinate of the mouse position.
    Point pt = e.GetPosition((UIElement)sender);

    // Perform the hit test against a given portion of the visual object tree.
    HitTestResult result = VisualTreeHelper.HitTest(myCanvas, pt);

    if (result != null)
    {
        // Perform action on hit visual object.
    }
}
' Respond to the left mouse button down event by initiating the hit test.
Private Overloads Sub OnMouseLeftButtonDown(ByVal sender As Object, ByVal e As MouseButtonEventArgs)
    ' Retrieve the coordinate of the mouse position.
    Dim pt As Point = e.GetPosition(CType(sender, UIElement))

    ' Perform the hit test against a given portion of the visual object tree.
    Dim result As HitTestResult = VisualTreeHelper.HitTest(myCanvas, pt)

    If result IsNot Nothing Then
        ' Perform action on hit visual object.
    End If
End Sub

Commenti

La VisualHit proprietà del valore restituito rappresenta l'oggetto Visual raggiunto.

Nota

È possibile che un hit test che inizia in un albero visivo 2D per restituire RayHitTestResult, che è un oggetto risultato di hit test 3D. Hit testing che inizia in un albero visivo 2D si estende facilmente in qualsiasi albero visivo 3D definito.

Vedi anche

Si applica a

HitTest(Visual3D, HitTestFilterCallback, HitTestResultCallback, HitTestParameters3D)

Avvia un hit test sull'oggetto Visual3D specificato, con metodi HitTestFilterCallback e HitTestResultCallback definiti dal chiamante.

public:
 static void HitTest(System::Windows::Media::Media3D::Visual3D ^ reference, System::Windows::Media::HitTestFilterCallback ^ filterCallback, System::Windows::Media::HitTestResultCallback ^ resultCallback, System::Windows::Media::Media3D::HitTestParameters3D ^ hitTestParameters);
public static void HitTest (System.Windows.Media.Media3D.Visual3D reference, System.Windows.Media.HitTestFilterCallback filterCallback, System.Windows.Media.HitTestResultCallback resultCallback, System.Windows.Media.Media3D.HitTestParameters3D hitTestParameters);
static member HitTest : System.Windows.Media.Media3D.Visual3D * System.Windows.Media.HitTestFilterCallback * System.Windows.Media.HitTestResultCallback * System.Windows.Media.Media3D.HitTestParameters3D -> unit
Public Shared Sub HitTest (reference As Visual3D, filterCallback As HitTestFilterCallback, resultCallback As HitTestResultCallback, hitTestParameters As HitTestParameters3D)

Parametri

reference
Visual3D

Visual3D per l'hit test.

filterCallback
HitTestFilterCallback

Metodo che rappresenta il valore di callback del filtro dell'hit test.

resultCallback
HitTestResultCallback

Metodo che rappresenta il valore di callback del risultato dell'hit test.

hitTestParameters
HitTestParameters3D

Valore di parametro 3D su cui eseguire l'hit test.

Commenti

Il filterCallback parametro può essere null, in questo caso, viene ignorato. Se filterCallback non nullè , viene richiamato prima resultCallbackdi . Il parametro resultCallback non può essere null.

Nota

È possibile che un hit test che inizia in un albero visivo 2D per restituire RayHitTestResult, che è un oggetto risultato di hit test 3D. Hit testing che inizia in un albero visivo 2D si estende facilmente in qualsiasi albero visivo 3D definito.

Si applica a

HitTest(Visual, HitTestFilterCallback, HitTestResultCallback, HitTestParameters)

Avvia un hit test sull'oggetto Visual specificato, con metodi HitTestFilterCallback e HitTestResultCallback definiti dal chiamante.

public:
 static void HitTest(System::Windows::Media::Visual ^ reference, System::Windows::Media::HitTestFilterCallback ^ filterCallback, System::Windows::Media::HitTestResultCallback ^ resultCallback, System::Windows::Media::HitTestParameters ^ hitTestParameters);
public static void HitTest (System.Windows.Media.Visual reference, System.Windows.Media.HitTestFilterCallback filterCallback, System.Windows.Media.HitTestResultCallback resultCallback, System.Windows.Media.HitTestParameters hitTestParameters);
static member HitTest : System.Windows.Media.Visual * System.Windows.Media.HitTestFilterCallback * System.Windows.Media.HitTestResultCallback * System.Windows.Media.HitTestParameters -> unit
Public Shared Sub HitTest (reference As Visual, filterCallback As HitTestFilterCallback, resultCallback As HitTestResultCallback, hitTestParameters As HitTestParameters)

Parametri

reference
Visual

Visual per l'hit test.

filterCallback
HitTestFilterCallback

Metodo che rappresenta il valore di callback del filtro dell'hit test.

resultCallback
HitTestResultCallback

Metodo che rappresenta il valore di callback del risultato dell'hit test.

hitTestParameters
HitTestParameters

Valore del parametro su cui eseguire di nuovo l'hit test.

Esempio

Nell'esempio seguente viene illustrato come usare il metodo per eseguire il HitTest test degli oggetti all'interno di un Canvasoggetto .

// Respond to the right mouse button down event by setting up a hit test results callback.
private void OnMouseRightButtonDown(object sender, MouseButtonEventArgs 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, null,
        new HitTestResultCallback(MyHitTestResult),
        new PointHitTestParameters(pt));

    // Perform actions on the hit test results list.
    if (hitResultsList.Count > 0)
    {
        Console.WriteLine("Number of Visuals Hit: " + hitResultsList.Count);
    }
}
' Respond to the right mouse button down event by setting up a hit test results callback.
Private Overloads Sub OnMouseRightButtonDown(ByVal sender As Object, ByVal e As MouseButtonEventArgs)
    ' 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, Nothing, New HitTestResultCallback(AddressOf MyHitTestResult), New PointHitTestParameters(pt))

    ' Perform actions on the hit test results list.
    If hitResultsList.Count > 0 Then
        Console.WriteLine("Number of Visuals Hit: " & hitResultsList.Count)
    End If
End Sub
// Return the result of the hit test to the callback.
public HitTestResultBehavior MyHitTestResult(HitTestResult result)
{
    // Add the hit test result to the list that will be processed after the enumeration.
    hitResultsList.Add(result.VisualHit);

    // Set the behavior to return visuals at all z-order levels.
    return HitTestResultBehavior.Continue;
}
' Return the result of the hit test to the callback.
Public Function MyHitTestResult(ByVal result As HitTestResult) As HitTestResultBehavior
    ' Add the hit test result to the list that will be processed after the enumeration.
    hitResultsList.Add(result.VisualHit)

    ' Set the behavior to return visuals at all z-order levels.
    Return HitTestResultBehavior.Continue
End Function

Commenti

Il filterCallback parametro può essere null, nel qual caso viene ignorato. Se filterCallback non nullè , viene richiamato prima resultCallbackdi . Il parametro resultCallback non può essere null.

Nota

È possibile che un hit test che inizia in un albero visivo 2D per restituire RayHitTestResult, che è un oggetto risultato di hit test 3D. Hit testing che inizia in un albero visivo 2D si estende facilmente in qualsiasi albero visivo 3D definito.

Vedi anche

Si applica a