Reputation: 122412
I'm using Silverlight 4. I have an ItemsControl
with a custom DataTemplate
. From that DataTemplate
, I would like to bind to something in the UserControl
's DataContext
- not the DataContext
of a specific element in the items control. Is there a way to do this?
Upvotes: 0
Views: 5504
Reputation: 276249
This should answer your question : Access parent DataContext from DataTemplate
<ItemsControl x:Name="level1Lister" ItemsSource={Binding MyLevel1List}>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button Content={Binding MyLevel2Property}
Command={Binding ElementName=level1Lister, Path=DataContext.MyLevel1Command}
CommandParameter={Binding MyLevel2Property}>
</Button>
<DataTemplate>
<ItemsControl.ItemTemplate>
</ItemsControl>
Upvotes: 5