問題描述:使用ObservableCollection<OrderItem> source 給Datagrid.ItemsSource賦值,在后台更新source集合后,前台Datagrid對應的單元格數據只有進行編輯模式才會獲得更新后的Source數據。
問題解決:如下代碼,數據源Model實現INotifyPropertyChanged接口,即可做到實時通知
注:ObservableCollection<OrderItem> source 替換為 List<OrderItem> 也可實現實時通知
public class OrderItem : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; private void NotifyPropertyChanged(string name) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(name)); } } private OpeType state; public OpeType State { get { return state; } set { state = value; NotifyPropertyChanged("State"); } } ...... }