开发者

Silverlight: Access parent data context from DataTemplate?

开发者 https://www.devze.com 2023-01-28 06:27 出处:网络
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 DataCo

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>
0

精彩评论

暂无评论...
验证码 换一张
取 消