views:

139

answers:

1

Is there anyway to stop automatic DataContext inheritance in Silverlight?

I Set my DataContext on my parent UserControl in code. As a result all the xaml bindings inside the UserControl try to bind to the new DataConext they get (through the automatic DataContext Inheritance).

The DataContext's for the children elements (actually they are children of children of children) of the UserControl is something I need to set in the UserControl's code... I don't want them being all smart because they end up binding to the wrong data object! :-)

+2  A: 

Can you set the DataContext to {x:Null} in XAML, or null in code, for the items you don't want the inherited context for?

Jeff Wilcox
That worked great, thanks heaps. I set the {x:Null} attribute on the starred element: "ParentGrid -> UserControl -> LayoutRoot -> ***ContainingCanvas*** -> Other Controls -> Binding ".This ensured the UserControl got its own context, and the low bindings did not try to reach back up because they found an explicitly set null value.
Ant