Ask Learn
Preview
Please sign in to use this experience.
Sign inThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Return top-most visual object of a hit test.
HitTest(Point) |
Returns the top-most visual object of a hit test by specifying a Point. |
HitTest(HitTestFilterCallback, HitTestResultCallback, HitTestParameters) |
Initiates a hit test on the ContainerVisual by using the HitTestFilterCallback and HitTestResultCallback objects. |
Returns the top-most visual object of a hit test by specifying a Point.
public:
System::Windows::Media::HitTestResult ^ HitTest(System::Windows::Point point);
public System.Windows.Media.HitTestResult HitTest(System.Windows.Point point);
override this.HitTest : System.Windows.Point -> System.Windows.Media.HitTestResult
member this.HitTest : System.Windows.Point -> System.Windows.Media.HitTestResult
Public Function HitTest (point As Point) As HitTestResult
The point value to hit test.
The hit test result of the visual returned as a HitTestResult type.
The following example shows how to retrieve the HitTestResult return value from the HitTest method.
// Capture the mouse event and hit test the coordinate point value against
// the child visual objects.
void MyVisualHost_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
// Retrieve the coordinates of the mouse button event.
Point pt = e.GetPosition((UIElement)sender);
// Initiate the hit test on the ContainerVisual's visual tree.
HitTestResult result = _containerVisual.HitTest(pt);
// Perform the action on the hit visual.
if (result.VisualHit != null)
{
ProcessHitVisual((Visual)result.VisualHit);
}
}
' Capture the mouse event and hit test the coordinate point value against
' the child visual objects.
Private Sub MyVisualHost_MouseLeftButtonUp(ByVal sender As Object, ByVal e As System.Windows.Input.MouseButtonEventArgs)
' Retrieve the coordinates of the mouse button event.
Dim pt As Point = e.GetPosition(CType(sender, UIElement))
' Initiate the hit test on the ContainerVisual's visual tree.
Dim result As HitTestResult = _containerVisual.HitTest(pt)
' Perform the action on the hit visual.
If result.VisualHit IsNot Nothing Then
ProcessHitVisual(CType(result.VisualHit, Visual))
End If
End Sub
The VisualHit property of the return value represents the Visual object that was hit.
Product | Versions |
---|---|
.NET Framework | 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
Windows Desktop | 3.0, 3.1, 5, 6, 7, 8, 9, 10 |
Initiates a hit test on the ContainerVisual by using the HitTestFilterCallback and HitTestResultCallback objects.
public:
void HitTest(System::Windows::Media::HitTestFilterCallback ^ filterCallback, System::Windows::Media::HitTestResultCallback ^ resultCallback, System::Windows::Media::HitTestParameters ^ hitTestParameters);
public void HitTest(System.Windows.Media.HitTestFilterCallback filterCallback, System.Windows.Media.HitTestResultCallback resultCallback, System.Windows.Media.HitTestParameters hitTestParameters);
override this.HitTest : System.Windows.Media.HitTestFilterCallback * System.Windows.Media.HitTestResultCallback * System.Windows.Media.HitTestParameters -> unit
member this.HitTest : System.Windows.Media.HitTestFilterCallback * System.Windows.Media.HitTestResultCallback * System.Windows.Media.HitTestParameters -> unit
Public Sub HitTest (filterCallback As HitTestFilterCallback, resultCallback As HitTestResultCallback, hitTestParameters As HitTestParameters)
The delegate that allows you to ignore parts of the visual tree that you are not interested in processing in your hit test results.
The delegate that is used to control the return of hit test information.
Defines the set of parameters for a hit test.
The filterCallback
parameter can be null, in which case, it is ignored. If filterCallback
is not null
, it is invoked before resultCallback
.
Product | Versions |
---|---|
.NET Framework | 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
Windows Desktop | 3.0, 3.1, 5, 6, 7, 8, 9, 10 |
.NET feedback
.NET is an open source project. Select a link to provide feedback:
Please sign in to use this experience.
Sign in