At runtime in a generic fashion (i.e. iterating UIElements) can I determine if a given FrameWorkElement has a non-inherited DataContext property set? I want a list of elements where DataContext was explicitly set, not inherited from higher up in the chain. I thought perhaps GetBindingExpression() would help but so far it has not. Using Silverlight beta 3.
A:
Definitely! Just compare the FrameworkElement Parent's DataContext using an equality operator.
It might not help in a situation where a child control has the DataContext set to the same exact item as the parent, but it would help in most scenarios.
Jeff Wilcox
2009-08-10 20:09:32