HitTestResultCallback HitTestResultCallback HitTestResultCallback HitTestResultCallback Delegate

Definición

Representa una devolución de llamada que se usa para personalizar la prueba de aciertos.Represents a callback that is used to customize hit testing. WPF invoca a HitTestResultCallback para informar de las intersecciones de la prueba de aciertos al usuario.WPF invokes the HitTestResultCallback to report hit test intersections to the user.

public delegate System::Windows::Media::HitTestResultBehavior HitTestResultCallback(HitTestResult ^ result);
public delegate System.Windows.Media.HitTestResultBehavior HitTestResultCallback(HitTestResult result);
type HitTestResultCallback = delegate of HitTestResult -> HitTestResultBehavior
Public Delegate Function HitTestResultCallback(result As HitTestResult) As HitTestResultBehavior 

Parámetros

result
HitTestResult HitTestResult HitTestResult HitTestResult

Valor HitTestResult que representa un objeto visual que se devuelve de una prueba de aciertos.The HitTestResult value that represents a visual object that is returned from a hit test.

Valor devuelto

System.Windows.Media.HitTestResultBehavior

HitTestFilterBehavior que representa la acción resultante de la prueba de aciertos.A HitTestFilterBehavior that represents the action resulting from the hit test.

Herencia
HitTestResultCallbackHitTestResultCallbackHitTestResultCallbackHitTestResultCallback

Ejemplos

El ejemplo siguiente muestra cómo invocar HitTest utilizando un HitTestResultCallback valor.The following example shows how to invoke HitTest by using a HitTestResultCallback value. También se define el método de devolución de llamada de prueba de posicionamiento correspondiente.The corresponding hit test callback method is also defined.

// 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)
{
    // Retreive the coordinates of the mouse button event.
    System.Windows.Point pt = e.GetPosition((UIElement)sender);

    // Initiate the hit test by setting up a hit test result callback method.
    VisualTreeHelper.HitTest(this, null, new HitTestResultCallback(myCallback), new PointHitTestParameters(pt));
}

// If a child visual object is hit, toggle its opacity to visually indicate a hit.
public HitTestResultBehavior myCallback(HitTestResult result)
{
    if (result.VisualHit.GetType() == typeof(DrawingVisual))
    {
        if (((DrawingVisual)result.VisualHit).Opacity == 1.0)
        {
            ((DrawingVisual)result.VisualHit).Opacity = 0.4;
        }
        else
        {
            ((DrawingVisual)result.VisualHit).Opacity = 1.0;
        }
    }

    // Stop the hit test enumeration of objects in the visual tree.
    return HitTestResultBehavior.Stop;
}
' 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 MouseButtonEventArgs)
	' Retreive the coordinates of the mouse button event.
	Dim pt As Point = e.GetPosition(CType(sender, UIElement))

	' Initiate the hit test by setting up a hit test result callback method.
	VisualTreeHelper.HitTest(Me, Nothing, New HitTestResultCallback(AddressOf myCallback), New PointHitTestParameters(pt))
End Sub

' If a child visual object is hit, toggle its opacity to visually indicate a hit.
Public Function myCallback(ByVal result As HitTestResult) As HitTestResultBehavior
	If result.VisualHit.GetType() Is GetType(DrawingVisual) Then
		If (CType(result.VisualHit, DrawingVisual)).Opacity = 1.0 Then
			CType(result.VisualHit, DrawingVisual).Opacity = 0.4
		Else
			CType(result.VisualHit, DrawingVisual).Opacity = 1.0
		End If
	End If

	' Stop the hit test enumeration of objects in the visual tree.
	Return HitTestResultBehavior.Stop
End Function

Comentarios

El método de devolución de llamada de prueba de posicionamiento define las acciones que se realizan cuando se identifica una prueba de posicionamiento en un objeto visual determinado del árbol visual.The hit test callback method defines the actions that you perform when a hit test is identified on a particular visual object in the visual tree. Después de realizar las acciones, la devolución de llamada debe devolver un HitTestResultBehavior valor que determina si se debe continuar la iteración a través del árbol visual para los demás objetos visuales.After you perform the actions, your callback is expected to return a HitTestResultBehavior value that determines whether to continue iterating through the visual tree for any other visual objects.

Extension Methods

GetMethodInfo(Delegate) GetMethodInfo(Delegate) GetMethodInfo(Delegate) GetMethodInfo(Delegate)

Obtiene un objeto que representa el método representado por el delegado especificado.Gets an object that represents the method represented by the specified delegate.

Se aplica a