Reputation: 2103
I'd like to display the property "Title" from a list of objects in a ListBox:
<ListBox ItemsSource="{Binding SelectableSurveysByYear}"
DisplayMemberPath="{Binding Title}"
SelectedItem="{Binding SelectedSurvey}">
However, instead of the titles, all I see is the name of my class, three times. SelectableSurveysByYear is an ObservableCollection of Surveys:
public class Survey
{
public string Title { get; set; }
}
Where is my flaw?
Upvotes: 0
Views: 320
Reputation: 4298
The DisplayMemberPath
property doesn't support the Binding
syntax. Try the following:
<ListBox ItemsSource="{Binding SelectableSurveysByYear}"
DisplayMemberPath="Title"
SelectedItem="{Binding SelectedSurvey}">
Upvotes: 2
Reputation: 2103
Oh.. the flaw was in defining DisplayMemberPath. This works:
<ListBox ItemsSource="{Binding SelectableSurveysByYear}"
DisplayMemberPath="Title"
SelectedItem="{Binding SelectedSurvey}">
Upvotes: 0