I'm looking for ways to effectively determine if a control is actually visible and clickable. I mean beyond checking Visibility property of the object.
I can check RenderSize and that would be [0,0] if any of the parent elements is collapsed. So this is simple too. I can also traverse up the visual tree and see if Opacity of all elements is set to 1.
What I don't know how to check nicely are these scenarios:
Update (one more scenario)
Any better ideas? Do I miss something?
Thanks!
You can programatically test the Visiblity and the HitTestVisible
property of an element, however beyond this you can't actually test if a click event will be forwarded to the element or swallowed by elements on top of it - because blocking or forwarding clicks can happen in event handler methods which you simply can't determine in a generic way.
Take the following example:
ParentElement
panel is clickable that has a ChildElement
on itChildElement
has an event handler attached to it that handles the click event, it's visible and its HitTestVisible
property is set to true. ParentElement
: in the click event handler of ChildElement
it can set the event's Handled
property to true that would stop the ParentPanel receiving the event or it could leave it at false, making the ParentPanel receive the event.Thus if there are custom EventHandlers involved, you won't be able to tell for certain whether an element is clickable or not. The most you can do is check the Visiblity
and IsHitTestVisible
properties on child and parent elements and check where the children / parents are rendered relative to each other using the TransformToVisual
method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With