Export (0) Print
Expand All

VisualTreeHelper.HitTest Method (Visual, HitTestFilterCallback, HitTestResultCallback, HitTestParameters)

Initiate a hit test on the Visual by using the HitTestFilterCallback and HitTestResultCallback objects.

Namespace: System.Windows.Media
Assembly: PresentationCore (in presentationcore.dll)

public static void HitTest (
	Visual reference,
	HitTestFilterCallback filterCallback,
	HitTestResultCallback resultCallback,
	HitTestParameters hitTestParameters
)
public static void HitTest (
	Visual reference, 
	HitTestFilterCallback filterCallback, 
	HitTestResultCallback resultCallback, 
	HitTestParameters hitTestParameters
)
public static function HitTest (
	reference : Visual, 
	filterCallback : HitTestFilterCallback, 
	resultCallback : HitTestResultCallback, 
	hitTestParameters : HitTestParameters
)
You cannot use methods in XAML.

Parameters

reference

The Visual to hit test.

filterCallback

The method that represents the hit test filter callback value.

resultCallback

The method that represents the hit test result callback value.

hitTestParameters

The parameter value to hit test against.

The filterCallback parameter can be a null reference (Nothing in Visual Basic), in which case it is ignored. If filterCallback is not a null reference (Nothing in Visual Basic), it is invoked before resultCallback.

NoteNote:

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 right mouse button down event by setting up a hit test results callback.
public 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);
    }
}

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0

Community Additions

ADD
Show:
© 2014 Microsoft