mirror of
https://github.com/Stone-Red-Code/docs-desktop.git
synced 2026-09-06 16:06:07 +02:00
* 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
36 lines
2.4 KiB
Markdown
36 lines
2.4 KiB
Markdown
---
|
|
title: "How to: Hit Test Geometry in a Visual"
|
|
ms.date: "03/30/2017"
|
|
dev_langs:
|
|
- "csharp"
|
|
- "vb"
|
|
helpviewer_keywords:
|
|
- "hit tests [WPF], on visual objects comprising Geometry objects [WPF]"
|
|
- "visual objects [WPF], hit tests on"
|
|
- "Geometry objects [WPF], visual objects comprising"
|
|
ms.assetid: 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-csharp[VisualsOverview#VisualsOverviewSnippet4](~/samples/snippets/csharp/VS_Snippets_Wpf/VisualsOverview/CSharp/Window1.xaml.cs#visualsoverviewsnippet4)]
|
|
[!code-vb[VisualsOverview#VisualsOverviewSnippet4](~/samples/snippets/visualbasic/VS_Snippets_Wpf/VisualsOverview/visualbasic/window1.xaml.vb#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.
|
|
|
|
## See also
|
|
|
|
- [Hit Testing in the Visual Layer](hit-testing-in-the-visual-layer.md)
|
|
- [Hit Test Using Geometry as a Parameter](how-to-hit-test-using-geometry-as-a-parameter.md)
|