Visual.HitTestCore 方法

定义

确定点或几何图形值是否在可视对象的边界内。Determines whether a point or geometry value is within the bounds of the visual object.

重载

HitTestCore(GeometryHitTestParameters)

确定可视对象的边界中是否存在几何图形值。Determines whether a geometry value is within the bounds of the visual object.

HitTestCore(PointHitTestParameters)

确定点坐标值是否在可视对象的边界内。Determines whether a point coordinate value is within the bounds of the visual object.

HitTestCore(GeometryHitTestParameters)

确定可视对象的边界中是否存在几何图形值。Determines whether a geometry value is within the bounds of the visual object.

protected:
 virtual System::Windows::Media::GeometryHitTestResult ^ HitTestCore(System::Windows::Media::GeometryHitTestParameters ^ hitTestParameters);
protected virtual System.Windows.Media.GeometryHitTestResult HitTestCore (System.Windows.Media.GeometryHitTestParameters hitTestParameters);
abstract member HitTestCore : System.Windows.Media.GeometryHitTestParameters -> System.Windows.Media.GeometryHitTestResult
override this.HitTestCore : System.Windows.Media.GeometryHitTestParameters -> System.Windows.Media.GeometryHitTestResult
Protected Overridable Function HitTestCore (hitTestParameters As GeometryHitTestParameters) As GeometryHitTestResult

参数

hitTestParameters
GeometryHitTestParameters

GeometryHitTestParameters 对象,指定 Geometry 针对命中测试。A GeometryHitTestParameters object that specifies the Geometry to hit test against.

返回

表示命中测试结果的 GeometryHitTestResult 对象。A GeometryHitTestResult that represents the result of the hit test.

示例

下面的示例演示如何重写 HitTestCore(GeometryHitTestParameters) 方法。The following example shows how to override the HitTestCore(GeometryHitTestParameters) method. 可能想要重写此方法的一个原因是在执行命中测试过程中提供附加功能。One reason you might want to override this method is to provide additional functionality during the hit testing process.

// Override default hit test support in visual object.
protected override GeometryHitTestResult HitTestCore(GeometryHitTestParameters hitTestParameters)
{
    IntersectionDetail intersectionDetail = IntersectionDetail.NotCalculated;

    // Perform custom actions during the hit test processing.

    return new GeometryHitTestResult(this, intersectionDetail);
}
' Override default hit test support in visual object.
Protected Overrides Overloads Function HitTestCore(ByVal hitTestParameters As GeometryHitTestParameters) As GeometryHitTestResult
    Dim intersectionDetail As IntersectionDetail = IntersectionDetail.NotCalculated

    ' Perform custom actions during the hit test processing.

    Return New GeometryHitTestResult(Me, intersectionDetail)
End Function

注解

可以通过重HitTestCore写方法来覆盖视觉对象的默认命中测试支持。You can override default hit testing support for a visual object by overriding the HitTestCore method. 这意味着, 当你调用HitTest方法时, 将调用的HitTestCore重写实现。This means that when you invoke the HitTest method, your overridden implementation of HitTestCore is called. 当命中测试位于可视对象的边框内时, 将调用重写的方法, 即使该坐标在视觉对象的几何图形之外也是如此。Your overridden method is called when a hit test falls within the bounding rectangle of the visual object, even if the coordinate falls outside the geometry of the visual object.

HitTestCore(PointHitTestParameters)

确定点坐标值是否在可视对象的边界内。Determines whether a point coordinate value is within the bounds of the visual object.

protected:
 virtual System::Windows::Media::HitTestResult ^ HitTestCore(System::Windows::Media::PointHitTestParameters ^ hitTestParameters);
protected virtual System.Windows.Media.HitTestResult HitTestCore (System.Windows.Media.PointHitTestParameters hitTestParameters);
abstract member HitTestCore : System.Windows.Media.PointHitTestParameters -> System.Windows.Media.HitTestResult
override this.HitTestCore : System.Windows.Media.PointHitTestParameters -> System.Windows.Media.HitTestResult
Protected Overridable Function HitTestCore (hitTestParameters As PointHitTestParameters) As HitTestResult

参数

hitTestParameters
PointHitTestParameters

PointHitTestParameters 对象,指定 Point 针对命中测试。A PointHitTestParameters object that specifies the Point to hit test against.

返回

表示从命中测试中返回的 HitTestResultVisualA HitTestResult that represents the Visual that is returned from a hit test.

示例

下面的示例演示如何重写 HitTestCore(PointHitTestParameters) 方法。The following example shows how to override the HitTestCore(PointHitTestParameters) method. 可能想要重写此方法的一个原因是在执行命中测试过程中提供附加功能。One reason you might want to override this method is to provide additional functionality during the hit testing process.

// Override default hit test support in visual object.
protected override HitTestResult HitTestCore(PointHitTestParameters hitTestParameters)
{
    Point pt = hitTestParameters.HitPoint;

    // Perform custom actions during the hit test processing,
    // which may include verifying that the point actually
    // falls within the rendered content of the visual.

    // Return hit on bounding rectangle of visual object.
    return new PointHitTestResult(this, pt);
}
' Override default hit test support in visual object.
Protected Overrides Overloads Function HitTestCore(ByVal hitTestParameters As PointHitTestParameters) As HitTestResult
    Dim pt As Point = hitTestParameters.HitPoint

    ' Perform custom actions during the hit test processing,
    ' which may include verifying that the point actually
    ' falls within the rendered content of the visual.

    ' Return hit on bounding rectangle of visual object.
    Return New PointHitTestResult(Me, pt)
End Function

注解

您可以通过重HitTestCore写方法来重写对视觉对象的默认命中测试支持。You can override the default hit testing support on visual objects by overriding the HitTestCore method. 这意味着, 当你调用HitTest方法时, 将调用的HitTestCore重写实现。This means that when you invoke the HitTest method, your overridden implementation of HitTestCore is called. 当命中测试位于可视对象的边框内时, 将调用重写的方法, 即使该坐标在视觉对象的几何图形之外也是如此。Your overridden method is called when a hit test falls within the bounding rectangle of the visual object, even if the coordinate falls outside the geometry of the visual object.

适用于