ContainerVisual.HitTest Method

Definition

Return top-most visual object of a hit test.

Overloads

HitTest(Point)

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

HitTest(HitTestFilterCallback, HitTestResultCallback, HitTestParameters)

Initiates a hit test on the ContainerVisual by using the HitTestFilterCallback and HitTestResultCallback objects.

HitTest(Point)

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

C#
public System.Windows.Media.HitTestResult HitTest(System.Windows.Point point);

Parameters

point
Point

The point value to hit test.

Returns

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

Examples

The following example shows how to retrieve the HitTestResult return value from the HitTest method.

C#
// Capture the mouse event and hit test the coordinate point value against
// the child visual objects.
void MyVisualHost_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
    // Retrieve the coordinates of the mouse button event.
    Point pt = e.GetPosition((UIElement)sender);

    // Initiate the hit test on the ContainerVisual's visual tree.
    HitTestResult result = _containerVisual.HitTest(pt);

    // Perform the action on the hit visual.
    if (result.VisualHit != null)
    {
        ProcessHitVisual((Visual)result.VisualHit);
    }
}

Remarks

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

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

HitTest(HitTestFilterCallback, HitTestResultCallback, HitTestParameters)

Initiates a hit test on the ContainerVisual by using the HitTestFilterCallback and HitTestResultCallback objects.

C#
public void HitTest(System.Windows.Media.HitTestFilterCallback filterCallback, System.Windows.Media.HitTestResultCallback resultCallback, System.Windows.Media.HitTestParameters hitTestParameters);

Parameters

filterCallback
HitTestFilterCallback

The delegate that allows you to ignore parts of the visual tree that you are not interested in processing in your hit test results.

resultCallback
HitTestResultCallback

The delegate that is used to control the return of hit test information.

hitTestParameters
HitTestParameters

Defines the set of parameters for a hit test.

Remarks

The filterCallback parameter can be null, in which case, it is ignored. If filterCallback is not null, it is invoked before resultCallback.

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10