Wpf binding with nested properties
Posted
by byte
on Stack Overflow
See other posts from Stack Overflow
or by byte
Published on 2010-05-13T13:34:09Z
Indexed on
2010/05/13
13:54 UTC
Read the original article
Hit count: 328
ViewModel
I have a property of type Member called KeyMember. The 'Member' type has an ObservableCollection called Addresses. The Address is composed of two strings - street and postcode .
View
I have a ListBox whose item source need to be set to ViewModels's KeyMember property and it should display the Street of all the Past Addresses in the collection.
Question
My ViewModel and View relationship is established properly.
I am able to write a data template for the above simple case as below
<ListBox ItemsSource="{Binding KeyMember.Addresses}">
<ListBox.ItemTemplate>
<DataTemplate DataType="Address">
<TextBlock Text="{Binding Street}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
How would I write the DataTemplate if I change KeyMember from type Member to ObservableCollection< Member > assuming that the collection has only one element.
PS: I know that for multiple elements in collection, I will have to implement the Master-Detail pattern/scenario.
© Stack Overflow or respective owner