HitTestFilterCallback 代理人
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
代表回調方法,指定視覺樹中部分部分要從命中測試處理中省略。
public delegate System::Windows::Media::HitTestFilterBehavior HitTestFilterCallback(DependencyObject ^ potentialHitTestTarget);
public delegate System.Windows.Media.HitTestFilterBehavior HitTestFilterCallback(DependencyObject potentialHitTestTarget);
type HitTestFilterCallback = delegate of DependencyObject -> HitTestFilterBehavior
Public Delegate Function HitTestFilterCallback(potentialHitTestTarget As DependencyObject) As HitTestFilterBehavior
參數
- potentialHitTestTarget
- DependencyObject
視覺測試。
傳回值
A HitTestFilterBehavior 代表命中測試所產生的動作。
範例
以下範例展示了如何使用HitTest一個值來調用HitTestFilterCallback。 同時也定義了對應的命中測試回撥方法。
// 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();
}
}
' Respond to the mouse wheel event by setting up a hit test filter and results enumeration.
Private Overloads Sub OnMouseWheel(ByVal sender As Object, ByVal e As MouseWheelEventArgs)
' Retrieve the coordinate of the mouse position.
Dim pt As Point = e.GetPosition(CType(sender, UIElement))
' 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(AddressOf MyHitTestFilter), New HitTestResultCallback(AddressOf MyHitTestResult), New PointHitTestParameters(pt))
' Perform actions on the hit test results list.
If hitResultsList.Count > 0 Then
ProcessHitTestResultsList()
End If
End Sub
以下範例展示了如何從命中測試過濾器回調方法回傳 HitTestFilterBehavior 一個值。
// 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;
}
}
' Filter the hit test values for each object in the enumeration.
Public Function MyHitTestFilter(ByVal o As DependencyObject) As HitTestFilterBehavior
' Test for the object value you want to filter.
If o.GetType() Is GetType(Label) Then
' 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
End If
End Function
備註
命中測試過濾器回調方法會對所有映射到命中測試條件的視覺物件被調用,從你指定的視覺物件開始,依序向下延伸至視覺樹的分支。 不過,您可能想要忽略點擊測試結果回呼函式中處理時不感興趣的視覺化樹狀結構特定分支。 命中測試篩選回呼函數的返回值決定了在列舉視覺物件時應採取的操作類型。 例如,如果你回傳值 ContinueSkipSelfAndChildren,你可以將當前的視覺物件及其後代從命中測試結果列舉中移除。 這表示命中測試結果回撥方法在其列舉中不會看到這些物件。
Note
剪除物件的視覺化樹狀結構會減少在點擊測試結果列舉通過期間的處理量。
修剪視覺樹
擴充方法
| 名稱 | Description |
|---|---|
| GetMethodInfo(Delegate) |
取得一個代表指定代理所代表方法的物件。 |