views:

242

answers:

1

I have a method which returns a generic list (from the db it returns a set of data to a list). I want to bind one property of that list to a combo box using ComboBox's ItemsSource="{Binding Path=ListFirstName}" property. How can i achive this? The code i tried

XAML code:

<ComboBox Name="cmbName"
         ItemsSource="{Binding Path=ExamineeList}"
         DisplayMemberPath="FirstName" />

XAML.cs code:

Examinee oExaminee = new Examinee();
List<Examinee> ExamineeList;
ExamineeList = oExaminee.ListAll(); //ListAll method returns a generic list 
cmbName.DataContext = ExamineeList;
+1  A: 

You're setting the ComboBox's DataContext to your list of Examinees in code, but then your XAML is trying to set its ItemsSource to a property called "ExamineeList". Since List<Examinee> has no property called "ExamineeList", the binding is not succeeding.

To tell the ComboBox to bind directly to its own DataContext, you can remove the Path from the binding:

<ComboBox Name="cmbName"
          ItemsSource="{Binding}"
          DisplayMemberPath="FirstName" />
Matt Hamilton
Thanks, It worked.
Stester