I am binding a List of object to a ComboBox.
<ComboBox Name="comboPerson" DisplayMemberPath="Name"/>
Where code behind looks like this:
List<Person> myFriends = new List<Person>()
{
new Person("Jack", "Daniels", 8),
new Person("Milla", "Jovovovich", 35),
new Person("Umma", "Turman", 34)
};
comboPerson.ItemsSource = myFriends;
And if I use standart Properties, it doesn't display the name but, if the property is accessed via get accessors it is working. Here is what I mean:
Working version:
public string Name { get; set; }
public string Surnamge { get; set; }
public int Age { get; set; }
public Person(string name, string surname, int age)
{
this.Name = name;
this.Surnamge = surname;
this.Age = age;
}
Non working version:
public string Name;
public string Surnamge;
public int Age;
public Person(string name, string surname, int age)
{
this.Name = name;
this.Surnamge = surname;
this.Age = age;
}
The question is: why WPF is unable to get the value from a standard Property?