HitTestFilterCallback 委托

定义

表示一种回叫方法,该方法指定可视化树中不进行命中测试处理的部分。

C#
public delegate System.Windows.Media.HitTestFilterBehavior HitTestFilterCallback(DependencyObject potentialHitTestTarget);

参数

potentialHitTestTarget
DependencyObject

要执行命中测试的视觉对象。

返回值

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

示例

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

C#
// Respond to the mouse wheel event by setting up a hit test filter and results enumeration.
private void OnMouseWheel(object sender, MouseWheelEventArgs e)
{
    // Retrieve the coordinate of the mouse position.
    Point pt = e.GetPosition((UIElement)sender);

    // Clear the contents of the list used for hit test results.
    hitResultsList.Clear();

    // Set up a callback to receive the hit test result enumeration.
    VisualTreeHelper.HitTest(myCanvas,
                      new HitTestFilterCallback(MyHitTestFilter),
                      new HitTestResultCallback(MyHitTestResult),
                      new PointHitTestParameters(pt));

    // Perform actions on the hit test results list.
    if (hitResultsList.Count > 0)
    {
        ProcessHitTestResultsList();
    }
}

以下示例演示如何从命中测试筛选器回调方法返回 HitTestFilterBehavior 值。

C#
// Filter the hit test values for each object in the enumeration.
public HitTestFilterBehavior MyHitTestFilter(DependencyObject o)
{
    // Test for the object value you want to filter.
    if (o.GetType() == typeof(Label))
    {
        // Visual object and descendants are NOT part of hit test results enumeration.
        return HitTestFilterBehavior.ContinueSkipSelfAndChildren;
    }
    else
    {
        // Visual object is part of hit test results enumeration.
        return HitTestFilterBehavior.Continue;
    }
}

注解

针对映射到命中测试条件的所有视觉对象调用命中测试筛选器回调方法,从指定的视觉对象开始,并一直降到可视化树的分支。 但是,你可能要忽略不希望在命中测试结果回调叫函数中处理的可视化树的某些分支。 命中测试筛选器回叫函数的返回值确定视觉对象的枚举应采用的操作类型。 例如,如果返回值 , ContinueSkipSelfAndChildren则可以从命中测试结果枚举中删除当前视觉对象及其后代。 这意味着命中测试结果回调方法在其枚举中看不到这些对象。

备注

修剪对象的可视化树会减少命中测试结果枚举传递期间的处理量。

使用命中测试筛选器修剪可视化树
修剪可视化树

扩展方法

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, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

另请参阅