Επεξεργασία

Κοινή χρήση μέσω


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.

public:
 System::Windows::Media::HitTestResult ^ HitTest(System::Windows::Point point);
public System.Windows.Media.HitTestResult HitTest (System.Windows.Point point);
override this.HitTest : System.Windows.Point -> System.Windows.Media.HitTestResult
member this.HitTest : System.Windows.Point -> System.Windows.Media.HitTestResult
Public Function HitTest (point As Point) As HitTestResult

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.

// 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);
    }
}
' Capture the mouse event and hit test the coordinate point value against
' the child visual objects.
Private Sub MyVisualHost_MouseLeftButtonUp(ByVal sender As Object, ByVal e As System.Windows.Input.MouseButtonEventArgs)
    ' Retrieve the coordinates of the mouse button event.
    Dim pt As Point = e.GetPosition(CType(sender, UIElement))

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

    ' Perform the action on the hit visual.
    If result.VisualHit IsNot Nothing Then
        ProcessHitVisual(CType(result.VisualHit, Visual))
    End If
End Sub

Remarks

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

Applies to

HitTest(HitTestFilterCallback, HitTestResultCallback, HitTestParameters)

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

public:
 void HitTest(System::Windows::Media::HitTestFilterCallback ^ filterCallback, System::Windows::Media::HitTestResultCallback ^ resultCallback, System::Windows::Media::HitTestParameters ^ hitTestParameters);
public void HitTest (System.Windows.Media.HitTestFilterCallback filterCallback, System.Windows.Media.HitTestResultCallback resultCallback, System.Windows.Media.HitTestParameters hitTestParameters);
override this.HitTest : System.Windows.Media.HitTestFilterCallback * System.Windows.Media.HitTestResultCallback * System.Windows.Media.HitTestParameters -> unit
member this.HitTest : System.Windows.Media.HitTestFilterCallback * System.Windows.Media.HitTestResultCallback * System.Windows.Media.HitTestParameters -> unit
Public Sub HitTest (filterCallback As HitTestFilterCallback, resultCallback As HitTestResultCallback, hitTestParameters As 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