1

I have an ObjectDataProvider defined as follows:

<ObjectDataProvider x:Key="employeeDataProvider" ObjectType="{x:Type cbb2:EmployeeAccess}" MethodName="getEmployees">            
</ObjectDataProvider>

As you can see the method getEmployees is called which returns a list of type Employee. The Employee class is defined as follows:

class Employee
{
    public string name { get; set; }
    public int id { get; set; }
}

My XAML page has a combo box that I want to populate with the employee name. Here is what I have so far:

<ComboBox ... ItemsSource="{Binding Source={StaticResource employeeDataProvider}}"/>

The problem I am having is the combo box is being populated with the Employee object and not the name property of the Employee.

Here is a picture of what's happening:

combo box

My question is, how to I get the combo box to populate with just the name property of the employee?

Thanks!

Jan Tacci
  • 3,131
  • 16
  • 63
  • 83

1 Answers1

1

add this property to the combo box

DisplayMemberPath="name"

eg:

<ComboBox DisplayMemberPath="name" ItemsSource="{Binding Source={StaticResource employeeDataProvider}}"/>
J King
  • 4,108
  • 10
  • 53
  • 103
  • Wow that was easy! I knew it was simple but I am so new to WPF (2 hours)! – Jan Tacci Apr 23 '13 at 04:27
  • Another quick question.. what if name was not defined as a property with get and set but rather with methods such as getName() and setName()? How would I access the name then? – Jan Tacci Apr 23 '13 at 04:39