Cette documentation est archivée et n’est pas conservée.

VisualTreeHelper.HitTest, méthode (Visual, Point)

Returns the top-most Visual object of a hit test by specifying a Point.

Espace de noms: System.Windows.Media
Assembly : PresentationCore (dans presentationcore.dll)

public static HitTestResult HitTest (
	Visual reference,
	Point point
)
public static HitTestResult HitTest (
	Visual reference, 
	Point point
)
public static function HitTest (
	reference : Visual, 
	point : Point
) : HitTestResult
Vous ne pouvez pas utiliser des méthodes dans XAML.

Paramètres

reference

The Visual to hit test.

point

The point value to hit test against.

Valeur de retour

The hit test result of the Visual returned as a HitTestResult type.

The VisualHit property of the return value represents the Visual object that was hit.

RemarqueRemarque :

It is possible for a hit test that starts in a 2D visual tree to return RayHitTestResult, which is a 3D hit test result object. Hit testing that starts in a 2D visual tree seamlessly extends into any defined 3D visual tree.

The following example shows how to use the HitTest method to hit test the objects within a Canvas.

// Respond to the left mouse button down event by initiating the hit test.
public 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.
    }
}

Microsoft .NET Framework 3.0 est pris en charge sur Windows Vista, Microsoft Windows XP SP2 et Windows Server 2003 SP1.

.NET Framework

Prise en charge dans : 3.0
Afficher: