HitTestResultCallback HitTestResultCallback HitTestResultCallback HitTestResultCallback Delegate

Definizione

Rappresenta un callback usato per personalizzare l'hit test.Represents a callback that is used to customize hit testing. WPF richiama l'oggetto HitTestResultCallback per segnalare le intersezioni di hit test all'utente.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 

Parametri

result
HitTestResult HitTestResult HitTestResult HitTestResult

Valore di HitTestResult che rappresenta un oggetto visivo restituito da un hit test.The HitTestResult value that represents a visual object that is returned from a hit test.

Valore restituito

System.Windows.Media.HitTestResultBehavior

Oggetto HitTestFilterBehavior che rappresenta l'azione risultante dell'hit test.A HitTestFilterBehavior that represents the action resulting from the hit test.

Ereditarietà
HitTestResultCallbackHitTestResultCallbackHitTestResultCallbackHitTestResultCallback

Esempi

Nell'esempio seguente viene illustrato come richiamare HitTest utilizzando un HitTestResultCallback valore.The following example shows how to invoke HitTest by using a HitTestResultCallback value. Viene definito anche il metodo di callback dell'hit test corrispondente.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)
{
    // Retrieve 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)
    ' Retrieve 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

Commenti

Il metodo di callback dell'hit test definisce le azioni che vengono eseguite quando viene identificato un hit test su un particolare oggetto visivo nella struttura ad albero visuale.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. Dopo aver eseguito le azioni, il callback dovrebbe restituire un HitTestResultBehavior valore che determina se continuare l'iterazione nella struttura ad albero visuale per eventuali altri oggetti visivi.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.

Metodi di estensione

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

Ottiene un oggetto che rappresenta il metodo rappresentato dal delegato specificato.Gets an object that represents the method represented by the specified delegate.

Si applica a