I need to be able to bind to a parent ItemsControl's properties from inside of a child ItemsControl data template:
<ItemsControl ItemsSource="{Binding Path=MyParentCollection, UpdateSourceTrigger=PropertyChanged}"> <ItemsControl.ItemTemplate> <DataTemplate> <ItemsControl ItemsSource="{Binding Path=MySubCollection}"> <ItemsControl.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding Path=MyParentCollection.Value, UpdateSourceTrigger=PropertyChanged}"/> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> Let's assume that MyParentCollection (the outer collection) is of the following type:
public class MyObject { public String Value { get; set; } public List<MyChildObject> MySubCollection { get; set; } And let's assume that MyChildObject from the above class is of the following type:
public class MyChildObject { public String Name { get; set; } } How can I bind to MyParentCollection.Value from inside of the inner data template? I can't really use a FindAncestor by type because they both all levels use the same types. I thought maybe I could put a name on the outer collection and use an ElementName tag in the inner binding, but that still couldn't resolve the property.
Any thoughts?