我定義個 List<Student> stuList = new List<Student>();
然后綁定 this.combobox1.ItemsSource =stuList;
我更新了一下stuList,然后再次綁定,這里就有異常了。
我想第二次更新了stuList后,讓Combobox也更新。
有兩種方法:
一種是將student類繼承notifychanged接口,然后把stuList的類型從list改ObservableCollection。這樣數據源更新了,Combobox會自動更新數據。
另一種,是在事件里,加入強制刷新的操作。this.combobox1.Item.Refresh();
MVVM模式下也適用。