HitTestResultCallback 委托

定义

表示用于自定义命中测试的回叫。 WPF 调用 HitTestResultCallback,向用户报告命中测试交集。

C#
public delegate System.Windows.Media.HitTestResultBehavior HitTestResultCallback(HitTestResult result);

参数

result
HitTestResult

HitTestResult 值,表示从命中测试返回的视觉对象。

返回值

HitTestResultBehavior

一个 HitTestFilterBehavior,它表示从命中测试中产生的操作。

示例

以下示例演示如何使用HitTestResultCallback值调用HitTest。 还定义了相应的命中测试回调方法。

C#
// 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;
}

注解

命中测试回调方法定义在可视化树中特定视觉对象上标识命中测试时执行的操作。 执行操作后,回调应返回一个 HitTestResultBehavior 值,该值确定是否继续遍历任何其他视觉对象的可视化树。

扩展方法

GetMethodInfo(Delegate)

获取指示指定委托表示的方法的对象。

适用于

产品 版本
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
Windows Desktop 3.0, 3.1, 5, 6, 7