Nic*_*ner 0 c# data-binding silverlight xaml
我正在使用Silverlight 4.我有ItemsControl一个自定义DataTemplate.从那以后DataTemplate,我想绑定到UserControl's中的某些东西DataContext- 而不是DataContextitem控件中的特定元素.有没有办法做到这一点?
这应该回答您的问题:从DataTemplate访问父DataContext
<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>
Run Code Online (Sandbox Code Playgroud)