1、创建类设置类属性
- class Person
- {
- public string name
- {
- set;
- get;
- }
- public int age
- {
- set;
- get;
- }
2、创建类对象,设置属性值
- private void Window_Loaded(object sender, RoutedEventArgs e)
- {
- List<Person> list = new List<Person>();
- Person P1 = new Person();
- P1.name = "张三";
- P1.age = 12;
- list.Add(P1);
- list.Add(new Person() {name="李四",age=18});
- lbPerson.ItemsSource = list;
- }
3、listbox控件绑定对象
- <ListBox DisplayMemberPath="属性" ></ListBox>