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?
Asked
Active
Viewed 5,498 times
0

Nick Heiner
- 119,074
- 188
- 476
- 699
1 Answers
5
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>
-
This doesn't seem to work with Silverlight. Rosarch are you using WPF or Silverlight? – akshayl Dec 10 '10 at 07:40
-
Its for silverlight 3 and above http://10rem.net/blog/2009/03/18/silverlight-3-–-ui-element-to-element-binding – basarat Dec 10 '10 at 08:55
-
Sorry to respond a bit late, but I was using Silverlight 4. – Nick Heiner Dec 29 '10 at 18:37
-
Silverlight 4 .. not sure why it isn't working, will have another look – akshayl Jan 06 '11 at 09:08