HitTestResultCallback 대리자

정의

적중 횟수 테스트를 사용자 지정하는 데 사용되는 콜백을 나타냅니다. WPF는 적중 횟수 테스트 교차 부분을 사용자에게 보고하기 위해 HitTestResultCallback을 호출합니다.

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 값입니다.

반환 값

HitTestResultBehavior

적중 횟수 테스트에서 발생하는 작업을 나타내는 HitTestFilterBehavior입니다.

예제

다음 예제에서는 호출 하는 방법을 보여 줍니다 HitTest 를 사용 하 여를 HitTestResultCallback 값입니다. 해당 하는 적중된 테스트 콜백 메서드 정의 됩니다.

// 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

설명

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

확장 메서드

GetMethodInfo(Delegate)

지정된 대리자가 나타내는 메서드를 나타내는 개체를 가져옵니다.

적용 대상