* 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
2.4 KiB
title, ms.date, dev_langs, helpviewer_keywords, ms.assetid
| title | ms.date | dev_langs | helpviewer_keywords | ms.assetid | |||||
|---|---|---|---|---|---|---|---|---|---|
| How to: Hit Test Geometry in a Visual | 03/30/2017 |
|
|
8bf2643f-d7f9-4cb4-9ea6-5b893c23200d |
How to: Hit Test Geometry in a Visual
This example shows how to perform a hit test on a visual object that is composed of one or more xref:System.Windows.Media.Geometry objects.
Example
The following example shows how to retrieve the xref:System.Windows.Media.DrawingGroup from a visual object that uses the xref:System.Windows.Media.VisualTreeHelper.GetDrawing%2A method. A hit test is then performed on the rendered content of each drawing in the xref:System.Windows.Media.DrawingGroup to determine which geometry was hit.
Note
In most cases, you would use the xref:System.Windows.Media.VisualTreeHelper.HitTest%2A method to determine whether a point intersects any of the rendered content of a visual.
[!code-csharpVisualsOverview#VisualsOverviewSnippet4] [!code-vbVisualsOverview#VisualsOverviewSnippet4]
The xref:System.Windows.Media.Geometry.FillContains%2A method is an overloaded method that allows you to hit test by using a specified xref:System.Windows.Point or xref:System.Windows.Media.Geometry. If a geometry is stroked, the stroke can extend outside the fill bounds. In which case, you may want to call xref:System.Windows.Media.Geometry.StrokeContains%2A in addition to xref:System.Windows.Media.Geometry.FillContains%2A.
You can also provide a xref:System.Windows.Media.ToleranceType that is used for the purposes of Bezier flattening.
Note
This sample does not take into account any transforms or clipping that may be applied to the geometry. In addition, this sample will not work with a styled control, since it does not have any drawings directly associated with it.