閱讀英文

共用方式為


HitTestFilterCallback 代理人

定義

表示回呼方法,指定要在點擊測試處理時略過的視覺化樹狀結構部分。

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

參數

potentialHitTestTarget
DependencyObject

要進行點擊測試的視覺化部分。

傳回值

HitTestFilterBehavior,表示從點擊測試產生的動作。

範例

下列範例示範如何使用 值叫 HitTestHitTestFilterCallback 。 也會定義對應的點擊測試回呼方法。

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

另請參閱