且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

更新WPF Datagrid中的单行

更新时间:2022-03-01 22:51:16

如果将DataGrid绑定到 ObservableCollection (它实现了 INotifyCollectionChanged ),当添加新项或删除某项时,您的DataGrid将会收到通知。此外,如果您只是更新集合中某个对象的属性,则该对象应实现 INotifyPropertyChanged 并引发PropertyChanged事件,该事件将告诉DataGrid仅更新该值。

If you bind your DataGrid to an ObservableCollection (which implements INotifyCollectionChanged) your DataGrid will be notified when a new item is added or an item is remove. Additionally, if you're just updating a property on an object in the collection the object should implement INotifyPropertyChanged and raise the PropertyChanged event which will tell the DataGrid to just update that value.