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?
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>
精彩评论