ContainerVisual.HitTest 方法

定義

傳回點擊測試最上層的視覺物件。

多載

HitTest(Point)

藉由指定 Point,傳回點擊測試最上層的視覺物件。

HitTest(HitTestFilterCallback, HitTestResultCallback, HitTestParameters)

使用 HitTestFilterCallbackHitTestResultCallback 物件,對 ContainerVisual 起始點擊測試。

HitTest(Point)

藉由指定 Point,傳回點擊測試最上層的視覺物件。

public:
 System::Windows::Media::HitTestResult ^ HitTest(System::Windows::Point point);
public System.Windows.Media.HitTestResult HitTest (System.Windows.Point point);
override this.HitTest : System.Windows.Point -> System.Windows.Media.HitTestResult
member this.HitTest : System.Windows.Point -> System.Windows.Media.HitTestResult
Public Function HitTest (point As Point) As HitTestResult

參數

point
Point

要進行點擊測試的點值。

傳回

視覺物件的點擊測試結果,作為 HitTestResult 類型傳回。

範例

下列範例示範如何從 HitTest 方法擷取 HitTestResult 傳回值。

// 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.
    Point pt = e.GetPosition((UIElement)sender);

    // Initiate the hit test on the ContainerVisual's visual tree.
    HitTestResult result = _containerVisual.HitTest(pt);

    // Perform the action on the hit visual.
    if (result.VisualHit != null)
    {
        ProcessHitVisual((Visual)result.VisualHit);
    }
}
' 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 System.Windows.Input.MouseButtonEventArgs)
    ' Retrieve the coordinates of the mouse button event.
    Dim pt As Point = e.GetPosition(CType(sender, UIElement))

    ' Initiate the hit test on the ContainerVisual's visual tree.
    Dim result As HitTestResult = _containerVisual.HitTest(pt)

    ' Perform the action on the hit visual.
    If result.VisualHit IsNot Nothing Then
        ProcessHitVisual(CType(result.VisualHit, Visual))
    End If
End Sub

備註

VisualHit 回值的 屬性代表 Visual 已叫用的物件。

適用於

HitTest(HitTestFilterCallback, HitTestResultCallback, HitTestParameters)

使用 HitTestFilterCallbackHitTestResultCallback 物件,對 ContainerVisual 起始點擊測試。

public:
 void HitTest(System::Windows::Media::HitTestFilterCallback ^ filterCallback, System::Windows::Media::HitTestResultCallback ^ resultCallback, System::Windows::Media::HitTestParameters ^ hitTestParameters);
public void HitTest (System.Windows.Media.HitTestFilterCallback filterCallback, System.Windows.Media.HitTestResultCallback resultCallback, System.Windows.Media.HitTestParameters hitTestParameters);
override this.HitTest : System.Windows.Media.HitTestFilterCallback * System.Windows.Media.HitTestResultCallback * System.Windows.Media.HitTestParameters -> unit
member this.HitTest : System.Windows.Media.HitTestFilterCallback * System.Windows.Media.HitTestResultCallback * System.Windows.Media.HitTestParameters -> unit
Public Sub HitTest (filterCallback As HitTestFilterCallback, resultCallback As HitTestResultCallback, hitTestParameters As HitTestParameters)

參數

filterCallback
HitTestFilterCallback

委派,可讓您忽略點擊測試結果中處理時不感興趣的視覺化樹狀結構組件。

resultCallback
HitTestResultCallback

用來控制如何傳回點擊測試資訊的委派。

hitTestParameters
HitTestParameters

定義點擊測試的參數集。

備註

參數 filterCallback 可以是 null,在此情況下會忽略它。 如果 filterCallback 不是 null ,則會在 之前 resultCallback 叫用它。

適用於