6

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?

snowy hedgehog
  • 652
  • 1
  • 7
  • 23

1 Answers1

10

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?

Community
  • 1
  • 1
Anatolii Gabuza
  • 6,184
  • 2
  • 36
  • 54