I’ve got a problem where I need to know about all the bindings that have been made to the dependency properties of my object.
Currently, I am iterating over the dependency properties whenever my datacontext changes, and looking for binding expressions. But I have discovered that in some cases (TabControls), the data context appears to be set first, then the bindings from XAML applied.
So, is there a way that I can detect a binding being applied to one of my dependency properties?
Assuming you are inside a UserControl, you should be able to use the Loaded event for this. That event is fired when “the element is laid out, rendered, and ready for interaction.” I can only assume this means that bindings have been completed.
You could then, in the
Loadedevent handler just tell your datacontext that you are binding to it.If you expect the datacontext to change, you’ll need to combine this with a
DataContextChangedevent handler as well.