HitTestResultCallback 代理人
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
表示用來自訂點擊測試的回呼。 WPF 叫用 HitTestResultCallback 將點擊的測試交集報告給使用者。
public delegate System::Windows::Media::HitTestResultBehavior HitTestResultCallback(HitTestResult ^ result);
public delegate System.Windows.Media.HitTestResultBehavior HitTestResultCallback(HitTestResult result);
type HitTestResultCallback = delegate of HitTestResult -> HitTestResultBehavior
Public Delegate Function HitTestResultCallback(result As HitTestResult) As HitTestResultBehavior
參數
- result
- HitTestResult
HitTestResult 值,表示從點擊測試傳回的視覺物件。
傳回值
HitTestFilterBehavior,表示從點擊測試產生的動作。
範例
下列範例示範如何使用 值叫 HitTest 用 HitTestResultCallback 。 也會定義對應的點擊測試回呼方法。
// 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;
}
' Capture the mouse event and hit test the coordinate point value against
' the child visual objects.
Private Sub MyVisualHost_MouseLeftButtonUp(ByVal sender As Object, ByVal e As MouseButtonEventArgs)
' Retrieve the coordinates of the mouse button event.
Dim pt As Point = e.GetPosition(CType(sender, UIElement))
' Initiate the hit test by setting up a hit test result callback method.
VisualTreeHelper.HitTest(Me, Nothing, New HitTestResultCallback(AddressOf myCallback), New PointHitTestParameters(pt))
End Sub
' If a child visual object is hit, toggle its opacity to visually indicate a hit.
Public Function myCallback(ByVal result As HitTestResult) As HitTestResultBehavior
If result.VisualHit.GetType() Is GetType(DrawingVisual) Then
If (CType(result.VisualHit, DrawingVisual)).Opacity = 1.0 Then
CType(result.VisualHit, DrawingVisual).Opacity = 0.4
Else
CType(result.VisualHit, DrawingVisual).Opacity = 1.0
End If
End If
' Stop the hit test enumeration of objects in the visual tree.
Return HitTestResultBehavior.Stop
End Function
備註
點擊測試回呼方法會定義您在視覺化樹狀結構中特定視覺物件上識別點擊測試時所執行的動作。 執行動作之後,您的回呼應該會傳回值,以判斷是否要繼續逐一 HitTestResultBehavior 查看任何其他視覺物件的視覺化樹狀結構。
擴充方法
GetMethodInfo(Delegate) |
取得表示特定委派所代表之方法的物件。 |