Search code examples
wpfeventsparentvisual-tree

How do I check for when my control obtains or changes the visual parent?


I want to hook my control's visual parent's events.


Solution

  • You can override the OnVisualParentChanged() method to be notified when ever your visual parent changes.

    Note that it is almost always a bad idea to actually use this: In 99% of cases the data template should take care of hooking up related controls by setting their properties, or it is better handled with attached inherited properties. But for the other 1% there is OnVisualParentChanged().