WPF Databinding: How do I access the "parent" data context?
You could try something like this:
...Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}, Path=DataContext.AllowItemCommand}" ...
This will also work:
<Hyperlink Command="{Binding RelativeSource={RelativeSource AncestorType=ItemsControl}, Path=DataContext.AllowItemCommand}" />
ListView
will inherit its DataContext
from Window
, so it's available at this point, too.
And since ListView
, just like similar controls (e. g. Gridview
, ListBox
, etc.), is a subclass of ItemsControl
, the Binding
for such controls will work perfectly.
This also works in Silverlight 5 (perhaps earlier as well but i haven't tested it). I used the relative source like this and it worked fine.
RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=telerik:RadGridView}"