I am doing some experiments and I am trying to collect all elements which are placed under mouse pointer.
XAML test code
<StackPanel>
<Button
x:Name="HitButton"
Content="Test Button" />
<Button
x:Name="NotHitButton"
IsHitTestVisible="False"
Content="Test Button" />
</StackPanel>
To get coordinates of mouse pointer I use PointerMoved
:
CoreWindow.GetForCurrentThread().PointerMoved += OnPointerMoved;
private void OnPointerMoved(CoreWindow sender, PointerEventArgs args)
{
Point point = args.CurrentPoint.Position;
IEnumerable<UIElement> elements = VisualTreeHelper.FindElementsInHostCoordinates(point, null, true);
...
}
This approach works, however, when a control has property IsHitTestVisible
set up to false
, FindElementsInHostCoordinates
does not consider it even if I set up the third parameter includeAllElements
of this method to true
.
According to documentation I would expect if I set the parameter includeAllElements
to true
, it should find all elements, including those controls which have IsHitTestVisible
set up to false
.
includeAllElements [System.Boolean]
true to include all elements that intersect, including those elements considered to be invisible to hit testing. false to find only visible, hit-testable elements. The default is false.
Do I understand wrong way how FindElementsInHostCoordinates
works? If so, is there any other way how to retrieve all controls at specific coordinates even if they have IsHitTestVisible
set to false
?