Windows apps
Collapse the table of content
Expand the table of content
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

HitTestFilterBehavior Enumeration


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Specifies the return behavior of a hit test in a hit test filter callback method.

Namespace:   System.Windows.Media
Assembly:  PresentationCore (in PresentationCore.dll)

Public Enumeration HitTestFilterBehavior

Member nameDescription

Hit test against the current Visual and its descendants.


Hit test against the current Visual, but not its descendants.


Do not hit test against the current Visual, but hit test against its descendants.


Do not hit test against the current Visual or its descendants.


Stop hit testing at the current Visual.

The return value of the hit test filter callback is a HitTestFilterBehavior, which determines what type of action should be taken when processing the visual tree for hit testing. For example, if your hit test filter callback return the value, ContinueSkipSelfAndChildren, you can remove the current visual object and its descendants from the hit test results evaluation.


Pruning the visual tree of objects decreases the amount of processing that is required during the hit test results evaluation pass.

Pruning a visual tree using a hit test filter

Pruning a visual tree

The following example shows how to return a HitTestFilterBehavior value from a hit test filter callback method. In this case, the filter skips labels and their descendants and hit tests everything else.

' Filter the hit test values for each object in the enumeration.
Public Function MyHitTestFilter(ByVal o As DependencyObject) As HitTestFilterBehavior
	' Test for the object value you want to filter.
	If o.GetType() Is GetType(Label) Then
		' Visual object and descendants are NOT part of hit test results enumeration.
		Return HitTestFilterBehavior.ContinueSkipSelfAndChildren
		' Visual object is part of hit test results enumeration.
		Return HitTestFilterBehavior.Continue
	End If
End Function

.NET Framework
Available since 3.0
Return to top
© 2018 Microsoft