Wpf binding with nested properties
- by byte
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.