I am currently looking for a way to be notified when a child is added to the visual or logical children.
I am aware of the Visual::OnVisualChildrenChanged method, but it does not apply to me since I can't always inherit and override this function. I am looking for an event.
So, is there a way for the owner of a FrameworkElement/Visual to be notified when a child is added?
Isn't it easier to extend
System.Windows.Controls.UIElementCollection
to do the notification and use
protected override UIElementCollection CreateUIElementCollection(FrameworkElement logicalParent)
?
I believe that FrameworkElement.Loaded and FrameworkElement.Unloaded are fired when the control is added to and removed from the Visual Tree, respectively. However, the few times that I was trying to do anything with them I wasn't able to get them to fire consistently (I was using Class Event Handlers at the time, so that might have something to do with it).
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