问题描述:
我打算选中列表中的字段,用文本框的值替换选中的字段。
然而在使用Binging将存放自定义类(Student)的集合绑定到ListBox上,显示的是这个类的“Name”属性。在修改这个属性后却没有看到列表中选中字段的变化。
ListBox取值绑定存储Sutdent类的对象。
之所以用ObservableCollection是因为:(出自《深入浅出WPF》)
ObservableCollection<Student> oc = new ObservableCollection<Student>();
public MainWindow()
{
InitializeComponent();
oc.Add(new Student("kobe"));
oc.Add(new Student("jordan"));
oc.Add(new Student("tracy"));
this.listBox.ItemsSource = oc;//绑定数据源为集合
this.listBox.DisplayMemberPath = "Name";//显示为Student类Name属性