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
要進行點擊測試的視覺化部分。
傳回值
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 則可以從點擊測試結果列舉中移除目前的視覺物件及其子系。 這表示點擊測試結果回呼方法不會在其列舉中看到這些物件。
注意
剪除物件的視覺化樹狀結構會減少在點擊測試結果列舉通過期間的處理量。
來剪
剪除視覺化樹狀結構
擴充方法
GetMethodInfo(Delegate) |
取得表示特定委派所代表之方法的物件。 |