I would like to know how to figure out when a control is visbile to user and when not?
Let says I am writing a custom control which extends a TextBox
and I would like to know when is visible to do some custom logic inside the handler triggered on visible changed.
How to do so? How to figure out if the control is visible to user or not? The custom control which extends a TextBox
could be inside a Button
for instance and Button
could receive Visibility.Collapsed
so all its inner nested controls would be invisibe and thats what I want to know. How to figure out if visible no matter what value to Visibility property is set?
You should use UIElement.IsVisibleChanged
event. It occurs when value of the IsVisible
changes that is read-only dependency property and indicates elements Visibility on UI. UIElement.LayoutUpdated
- event that could be used for recalculating controls visibility.
UPDATE.
Seems like it is exact duplicate:
In WPF, how can I determine whether a control is visible to the user?
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