in WPF when using VisualTreeHelper.HitTest
even hidden Elements are found. To skip this elements and only return a result for visible ones, i created a HitTestFilter
like the following :
///This Filter should cut all invisible or not HitTest Enabled Elements
private static HitTestFilterBehavior MyHitTestFilter(DependencyObject target)
{
var uiElement = target as UIElement;
if (uiElement != null){
if(!uiElement.IsHitTestVisible || !uiElement.IsVisible))
return HitTestFilterBehavior.ContinueSkipSelfAndChildren;
}
return HitTestFilterBehavior.Continue;
}
This Filter does his job, but i like to know what the default WPF HitTesting does in this case? Does it use a similar filter? Are there any other, maybe better options for doing this?
To clarify a short description :
In the image there is
- A Layout Container as the root element
- Button1 which is visible
- Above Button1 is Button2 which is invisible
If i got such a layout and do a mouseclick in the green area of Button2, WPF skips Button2 and the click event appears on Button1.
If i do manual HitTesting without the filter described earlier, i will get Button2 as the result.
So the question is, what is the default behaviour/filter WPF is using?
Thanks in advance for any suggestions.