VisualTreeHelper.HitTest Yöntem

Tanım

İsabet testinin en üstteki Visual nesnesini döndürür.

Aşırı Yüklemeler

HitTest(Visual, Point)

bir belirterek Pointisabet testinin en üstteki Visual nesnesini döndürür.

HitTest(Visual3D, HitTestFilterCallback, HitTestResultCallback, HitTestParameters3D)

Belirtilen Visual3Düzerinde çağıran tanımlı HitTestFilterCallback ve HitTestResultCallback yöntemleriyle bir isabet testi başlatır.

HitTest(Visual, HitTestFilterCallback, HitTestResultCallback, HitTestParameters)

Belirtilen Visualüzerinde çağıran tanımlı HitTestFilterCallback ve HitTestResultCallback yöntemleriyle bir isabet testi başlatır.

Açıklamalar

ve HitTestFilterCallback parametrelerini alan HitTestResultCallback aşırı yüklenmiş yöntemler, isabet testi sırasında ek işlevsellik sağlar:

  • Isabet testi sırasında görsel ağaç geçişi denetimine katılmanıza izin verir.

  • Yalnızca en üstteki değil nokta veya geometrinin altındaki tüm görselleri almanıza olanak sağlar.

HitTest(Visual, Point)

bir belirterek Pointisabet testinin en üstteki Visual nesnesini döndürür.

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

Parametreler

reference
Visual

Isabet Visual testi.

point
Point

Teste karşı isabet etmek için nokta değeri.

Döndürülenler

HitTestResult

öğesinin Visualisabet testi sonucu bir HitTestResult tür olarak döndürülür.

Örnekler

Aşağıdaki örnekte içindeki nesneleri Canvastest etmek için yönteminin nasıl kullanılacağı HitTest gösterilmektedir.

// 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

Açıklamalar

VisualHit dönüş değerinin özelliği, isabet edilen Visual nesneyi temsil eder.

Not

2B görsel ağacında başlayan bir isabet testinin, bir 3B isabet testi sonuç nesnesi olan değerini döndürmesi RayHitTestResultmümkündür. 2B görsel ağacında başlayan isabet testi, tanımlı herhangi bir 3B görsel ağacına sorunsuz bir şekilde genişletir.

Ayrıca bkz.

Şunlara uygulanır

HitTest(Visual3D, HitTestFilterCallback, HitTestResultCallback, HitTestParameters3D)

Belirtilen Visual3Düzerinde çağıran tanımlı HitTestFilterCallback ve HitTestResultCallback yöntemleriyle bir isabet testi başlatır.

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)

Parametreler

reference
Visual3D

Isabet Visual3D testi.

filterCallback
HitTestFilterCallback

İsabet testi filtre geri çağırma değerini temsil eden yöntem.

resultCallback
HitTestResultCallback

İsabet testi sonucu geri çağırma değerini temsil eden yöntem.

hitTestParameters
HitTestParameters3D

Teste karşı isabet etmek için 3B parametre değeri.

Açıklamalar

filterCallback parametresi olabilirnull, bu durumda yoksayılır. nulldeğilsefilterCallback, öncesinde resultCallbackçağrılır. resultCallback olamaz null.

Not

2B görsel ağacında başlayan bir isabet testinin, bir 3B isabet testi sonuç nesnesi olan değerini döndürmesi RayHitTestResultmümkündür. 2B görsel ağacında başlayan isabet testi, tanımlı herhangi bir 3B görsel ağacına sorunsuz bir şekilde genişletir.

Şunlara uygulanır

HitTest(Visual, HitTestFilterCallback, HitTestResultCallback, HitTestParameters)

Belirtilen Visualüzerinde çağıran tanımlı HitTestFilterCallback ve HitTestResultCallback yöntemleriyle bir isabet testi başlatır.

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)

Parametreler

reference
Visual

Isabet Visual testi.

filterCallback
HitTestFilterCallback

İsabet testi filtre geri çağırma değerini temsil eden yöntem.

resultCallback
HitTestResultCallback

İsabet testi sonucu geri çağırma değerini temsil eden yöntem.

hitTestParameters
HitTestParameters

Sınamaya karşı isabet etmek için parametre değeri.

Örnekler

Aşağıdaki örnekte içindeki nesneleri Canvastest etmek için yönteminin nasıl kullanılacağı HitTest gösterilmektedir.

// 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

Açıklamalar

filterCallback parametresi olabilir nullve bu durumda yoksayılır. nulldeğilsefilterCallback, öncesinde resultCallbackçağrılır. resultCallback olamaz null.

Not

2B görsel ağacında başlayan bir isabet testinin, bir 3B isabet testi sonuç nesnesi olan değerini döndürmesi RayHitTestResultmümkündür. 2B görsel ağacında başlayan isabet testi, tanımlı herhangi bir 3B görsel ağacına sorunsuz bir şekilde genişletir.

Ayrıca bkz.

Şunlara uygulanır