you can do something like this, but this is per control
DependencyPropertyDescriptor dpd = DependencyPropertyDescriptor.FromProperty(TextBox.TextProperty,typeof(TextBox));dpd.AddValueChanged(txt1,
new EventHandler(callback));
Is it that you're only interested in a specific property or you really want to know about every potential property change If the former, then you can walk the descendants of the logical tree of the Grid, determine if they're textboxes and hook up for property change notification using DependencyPropertyDescriptor::AddValueChanged. If the latter, while possible, I'd highly recommend against it and maybe with more detail I can provide a better solution.
Later,
Drew
No it should be as generic as possible. What I want is this: I created a custom panel that has an event called TextboxTextChanged. This event should be fired whenever both of the conditions are true:
Drew Marsh wrote:
... If the former, then you can walk the descendants of the logical tree of the Grid, determine if they're textboxes and hook up for property change notification using DependencyPropertyDescriptor::AddValueChanged. If the latter, while possible, I'd highly recommend against it and maybe with more detail I can provide a better solution.
Later,
Drew
When do I walk the children Since the children can change I would need to walk the children everytime a direct or indirect child was added or removed, only to determine if the panel currently has children that are textboxes.
Lee's answer is right on. All text boxes will route their TextChanged event up through the Grid. You need only listen to the event at the Grid level and WPF will take care of notifying you.
Later,
Drew
My concrete scenario is solved with the routedevent approach. So my last question was more a theoretical one. I could well imagine that some day I run into the same problem only with a property where the appropiate RoutedEvent does not exist. Let me try to make up a scenario:
Suppose I have a panel that should change its backgroundcolor based on backgroundcolors of its childelements. So whenever one of the panels direct or indirect children changes its Control.BackgroundPorperty (for example to make sure that the background of the panel is never the same as the background of its children) the panel needs to be notified upon each children's BackgroundPorperty change, because it has to recalculate its own background color now. Since there is no Control.BackgroundChanged I can not go with the RoutedEvent approach ...
lee d wrote:
you can just iterate over the children