0

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?

2 Answers 2

2

The DisplayMemberPath property doesn't support the Binding syntax. Try the following:

<ListBox ItemsSource="{Binding SelectableSurveysByYear}"
     DisplayMemberPath="Title" 
     SelectedItem="{Binding SelectedSurvey}">
Sign up to request clarification or add additional context in comments.

Comments

0

Oh.. the flaw was in defining DisplayMemberPath. This works:

   <ListBox ItemsSource="{Binding SelectableSurveysByYear}"
         DisplayMemberPath="Title" 
         SelectedItem="{Binding SelectedSurvey}">

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.