HitTestResultCallback 대리자

정의

적중 횟수 테스트를 사용자 지정하는 데 사용되는 콜백을 나타냅니다.Represents a callback that is used to customize hit testing. WPF는 적중 횟수 테스트 교차 부분을 사용자에게 보고하기 위해 HitTestResultCallback을 호출합니다.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 

매개 변수

result
HitTestResult

적중 횟수 테스트에서 반환되는 시각적 개체를 나타내는 HitTestResult 값입니다.The HitTestResult value that represents a visual object that is returned from a hit test.

반환 값

HitTestResultBehavior

적중 횟수 테스트에서 발생하는 작업을 나타내는 HitTestFilterBehavior입니다.A HitTestFilterBehavior that represents the action resulting from the hit test.

상속
HitTestResultCallback

예제

다음 예제에서는 호출 하는 방법을 보여 줍니다 HitTest 를 사용 하 여를 HitTestResultCallback 값입니다.The following example shows how to invoke HitTest by using a HitTestResultCallback value. 해당 하는 적중된 테스트 콜백 메서드 정의 됩니다.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

설명

적중된 테스트 콜백 메서드는 시각적 트리의 특정 시각적 개체에는 적중된 테스트가 식별 될 때 수행 하는 작업을 정의 합니다.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. 작업을 수행한 후에 콜백을 반환 해야 하는 HitTestResultBehavior 다른 시각적 개체에 대 한 시각적 트리를 통해 반복을 계속할지 여부를 결정 하는 값입니다.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.

확장 메서드

GetMethodInfo(Delegate)

지정된 대리자가 나타내는 메서드를 나타내는 개체를 가져옵니다.Gets an object that represents the method represented by the specified delegate.

적용 대상