Reputation:
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 ComboBox
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;
Upvotes: 0
Views: 3763
Reputation: 204259
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" />
Upvotes: 4