GeometryHitTestParameters 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
指定 Geometry 作为用于命中测试可视化树的参数。
public ref class GeometryHitTestParameters : System::Windows::Media::HitTestParameters
public class GeometryHitTestParameters : System.Windows.Media.HitTestParameters
type GeometryHitTestParameters = class
inherit HitTestParameters
Public Class GeometryHitTestParameters
Inherits HitTestParameters
- 继承
示例
以下示例演示如何使用GeometryHitTestParametersHitTest该方法设置命中测试。 Point传递给OnMouseDown该方法的值用于创建Geometry对象,以便扩展命中测试的范围。
// Respond to the mouse button down event by setting up a hit test results callback.
private void OnMouseDown(object sender, MouseButtonEventArgs e)
{
// Retrieve the coordinate of the mouse position.
Point pt = e.GetPosition((UIElement)sender);
// Expand the hit test area by creating a geometry centered on the hit test point.
EllipseGeometry expandedHitTestArea = new EllipseGeometry(pt, 10.0, 10.0);
// 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(myControl, null,
new HitTestResultCallback(MyHitTestResultCallback),
new GeometryHitTestParameters(expandedHitTestArea));
// Perform actions on the hit test results list.
if (hitResultsList.Count > 0)
{
ProcessHitTestResultsList();
}
}
' Respond to the mouse button down event by setting up a hit test results callback.
Private Overloads Sub OnMouseDown(ByVal sender As Object, ByVal e As MouseButtonEventArgs)
' Retrieve the coordinate of the mouse position.
Dim pt As Point = e.GetPosition(CType(sender, UIElement))
' Expand the hit test area by creating a geometry centered on the hit test point.
Dim expandedHitTestArea As New EllipseGeometry(pt, 10.0, 10.0)
' 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(myControl, Nothing, New HitTestResultCallback(AddressOf MyHitTestResultCallback), New GeometryHitTestParameters(expandedHitTestArea))
' Perform actions on the hit test results list.
If hitResultsList.Count > 0 Then
ProcessHitTestResultsList()
End If
End Sub
该 IntersectionDetail 属性 GeometryHitTestResult 提供有关使用 Geometry 命中测试参数的命中测试结果的信息。 下图显示了命中测试几何图形 (蓝色圆) 与目标对象 (红方) 之间的关系。

命中测试几何图形和目标对象之间的交集
注解
使用 GeometryHitTestParameters 类,可以使用值 Geometry 进行测试,以确定任何视觉对象是否与 Geometry 值相交。
还可以通过创建PointHitTestParameters对象来命中测试Point值。
备注
Windows Presentation Foundation (WPF) 命中测试仅考虑命中测试期间几何图形的填充区域。 如果创建点 Geometry,则命中测试不会相交任何内容,因为某个点没有区域。
构造函数
| GeometryHitTestParameters(Geometry) |
使用指定的 Geometry 初始化 GeometryHitTestParameters 类的新实例。 |
属性
| HitGeometry |
获取为此 GeometryHitTestParameters 实例定义命中测试几何图形的 Geometry。 |
方法
| Equals(Object) |
确定指定对象是否等于当前对象。 (继承自 Object) |
| GetHashCode() |
作为默认哈希函数。 (继承自 Object) |
| GetType() |
获取当前实例的 Type。 (继承自 Object) |
| MemberwiseClone() |
创建当前 Object 的浅表副本。 (继承自 Object) |
| ToString() |
返回表示当前对象的字符串。 (继承自 Object) |