【发布时间】:2014-09-09 20:58:20
【问题描述】:
我一直在研究 BindingList 与 observablecollection 和 List 之间的区别。从我读过的内容来看,似乎 BindingList 是唯一会通知其中的对象是否更改了其属性之一的集合类型。我无法让它工作。
我在 ViewModel 上有一个名为 Matches 的属性,它返回一个从另一个类中的 CarMatch 对象列表创建的 BindingList。 (Cars m_Cars = new Cars();) 我在 View 上的 DataGrid 绑定到 VM 中的这个 Matches 属性。
public BindingList<CarMatch> Matches
{
get
{
Return new BindingList<CarMatch>(m_Cars.Matches);
}
}
现在,在代码中,我更改了 CarMatch 对象的属性之一,例如,从 false 到 autoTrans = true。匹配[0].automaticTrans = true。我想在 DataGrid 中看到这种变化。如果没有在 CarMatch 类中实现 INotifyPropertyChanged,有没有办法从视图模型更新数据网格?在 Matches 上使用 INotifyPropertyChanged 似乎并没有这样做。这个有点不明白,可以举个例子看看。
【问题讨论】: