Files
docs-desktop/dotnet-desktop-guide/framework/wpf/graphics-multimedia/how-to-hit-test-using-geometry-as-a-parameter.md
T
Andy De George da363692ff Initial WPF content migrated (#17)
* Reset branch for WPF changes

* Convert BMP to PNG; fix link-out-of-scope err

* Add snippets for WPF... 6794 files!!!!

* Add missing snippets

* update file updated between migration

* Fix paths to include

* update breadcrumb and toc

* fix index links

* fix index links

* fix index links

* fix markdown
2020-09-04 09:46:28 -07:00

3.2 KiB

title, ms.date, dev_langs, helpviewer_keywords, ms.assetid
title ms.date dev_langs helpviewer_keywords ms.assetid
How to: Hit Test Using Geometry as a Parameter 03/30/2017
csharp
vb
hit tests [WPF], on visual objects using Geometry objects [WPF]
visual objects [WPF], hit tests on
Geometry objects [WPF], hit tests on visual objects [WPF]
6c8bdbf2-19e0-4fbb-bf89-c1252b2ebc61

How to: Hit Test Using Geometry as a Parameter

This example shows how to perform a hit test on a visual object using a xref:System.Windows.Media.Geometry as a hit test parameter.

Example

The following example shows how to set up a hit test using xref:System.Windows.Media.GeometryHitTestParameters for the xref:System.Windows.Media.VisualTreeHelper.HitTest%2A method. The xref:System.Windows.Point value that is passed to the OnMouseDown method is used to create a xref:System.Windows.Media.Geometry object in order to expand the range of the hit test.

[!code-csharpHitTestingOverview#HitTestingOverviewSnippet10] [!code-vbHitTestingOverview#HitTestingOverviewSnippet10]

The xref:System.Windows.Media.GeometryHitTestResult.IntersectionDetail%2A property of xref:System.Windows.Media.GeometryHitTestResult provides information about the results of a hit test that uses a xref:System.Windows.Media.Geometry as a hit test parameter. The following illustration shows the relationship between the hit test geometry (the blue circle) and the rendered content of the target visual object (the red square).

Diagram that shows IntersectionDetail used in hit testing.

The following example shows how to implement a hit test callback when a xref:System.Windows.Media.Geometry is used as a hit test parameter. The result parameter is cast to a xref:System.Windows.Media.GeometryHitTestResult in order to retrieve the value of the xref:System.Windows.Media.GeometryHitTestResult.IntersectionDetail%2A property. The property value allows you to determine if the xref:System.Windows.Media.Geometry hit test parameter is fully or partially contained within the rendered content of the hit test target. In this case, the sample code is only adding hit test results to the list for visuals that are fully contained within the target boundary.

[!code-csharpHitTestingOverview#HitTestingOverviewSnippet11] [!code-vbHitTestingOverview#HitTestingOverviewSnippet11]

Note

The xref:System.Windows.Media.HitTestResult callback should not be called when the intersection detail is xref:System.Windows.Media.IntersectionDetail.Empty.

See also