Skip to main content
.NET Framework Class Library
GeometryHitTestParameters Class

Specifies a Geometry as the parameter to be used for hit testing a visual tree.

Inheritance Hierarchy
SystemObject
   System.Windows.MediaHitTestParameters
    System.Windows.MediaGeometryHitTestParameters

Namespace:   System.Windows.Media
Assembly:  PresentationCore (in PresentationCore.dll)
Syntax
Public Class GeometryHitTestParameters _
	Inherits [%$TOPIC/ms634993_en-us_VS_110_3_0_0_0_0%]
public class GeometryHitTestParameters : [%$TOPIC/ms634993_en-us_VS_110_3_0_1_0_0%]
public ref class GeometryHitTestParameters : public [%$TOPIC/ms634993_en-us_VS_110_3_0_2_0_0%]
type GeometryHitTestParameters =  
    class 
        inherit [%$TOPIC/ms634993_en-us_VS_110_3_0_3_0_0%] 
    end
public class GeometryHitTestParameters extends [%$TOPIC/ms634993_en-us_VS_110_3_0_4_0_0%]

The GeometryHitTestParameters type exposes the following members.

Constructors
  NameDescription
Public method GeometryHitTestParametersInitializes a new instance of the GeometryHitTestParameters class, using the specified Geometry.
Top
Properties
  NameDescription
Public property HitGeometryGets the Geometry that defines the hit test geometry for this GeometryHitTestParameters instance.
Top
Methods
  NameDescription
Public method Equals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected method FinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method GetHashCodeServes as the default hash function. (Inherited from Object.)
Public method GetTypeGets the Type of the current instance. (Inherited from Object.)
Protected method MemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public method ToStringReturns a string that represents the current object. (Inherited from Object.)
Top
Remarks

With the GeometryHitTestParameters class, you can use a Geometry value for hit testing, to determine whether any visual object intersects with the Geometry value.

You can also hit test with a Point value by creating a PointHitTestParameters object.

NoteNote

Windows Presentation Foundation (WPF) hit testing only considers the filled area of a geometry during a hit test. If you create a point Geometry, the hit test would not intersect anything because a point has no area.

Examples

The following example shows how to set up a hit test using GeometryHitTestParameters for the HitTest method. The Point value that is passed to the OnMouseDown method is used to create a Geometry object in order to expand the range of the hit test.

		' 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
// 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();
    }
}

The IntersectionDetail property of GeometryHitTestResult provides information about the results of a hit test that uses a Geometry as a hit test parameter. The following illustration shows the relationship between the hit test geometry (the blue circle) and the target object (the red square).

Intersection between hit test geometry and target object

Diagram of IntersectionDetail used in hit testing
Version Information

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.