Use a relative source or element name binding to walk up to the parent element.
Something like:
ItemsSource="{Binding Path=DataContext.LookupList,
RelativeSource={RelativeSource FindAncestor, AncestorType=ListBox}}"
It's about time we had some Razor-like innovation in WPF
Paul
________________________________
From: [email protected] [[email protected]] on behalf of
Greg Keogh [[email protected]]
Sent: Tuesday, December 27, 2011 11:27 AM
To: 'ozWPF'
Subject: Another binding question
Folks, I’ll get back to you next week about how to perform entity-level
validation. I’m just digesting the replies from last week and will return to
the problem next week.
In the meantime I’ve got another binding conundrum, this time about “nested”
binding. The skeleton of my code looks like this:
class MyController
{
public IEnumerable<MyThing> ThingList { ... }
public IEnumerable<MyLookup> LookupList { ... }
}
class MyControl
{
MyController controller = new MyController();
DataContext = controller;
}
<ListBox ItemsSource="{Binding ThingList}">
<DataTemplate>
<TextBlock Text="{Binding Name}" .../>
<ComboBox ItemsSource="{Binding LookupList}" .../>
</DataTemplate>
</ListBox>
Like a schoolbook example, you can see that the ListBox binds to the ThingList
and shows each item correctly. The trouble is the red text which is a
lookup/picker list for each item. I see binding debug error messages telling me
that LookupList is not found, because it’s not a property of MyThing.
I don’t know how to tell the ComboBox in each item to bind to LookupList and
not to some property of the bound item. I’ve tried various tricks in the
binding cheat sheet without luck.
Cheers,
Greg
_______________________________________________
ozwpf mailing list
[email protected]
http://prdlxvm0001.codify.net/mailman/listinfo/ozwpf