C# 未更新Datagrid行详细信息

C# 未更新Datagrid行详细信息,c#,wpf,xaml,mvvm,wpfdatagrid,C#,Wpf,Xaml,Mvvm,Wpfdatagrid,在修改数据网格绑定到的集合(“项”)时,我在更新行详细信息模板时遇到问题。正在从视图模型中修改集合。修改其中一个绑定项的内容时,DataGridRow和RowDetailsTemplate中的更改都会更新。例如 Items[i].Name = "new name"; // RowDetailsTemplate gets updated 但是,如果我将其中一个项分配给一个全新的对象,DataGridRow将更新,但RowDetailsTemplate不会更新。例如 Items[i] = new

在修改
数据网格
绑定到的集合(“项”)时,我在更新
行详细信息模板
时遇到问题。正在从视图模型中修改集合。修改其中一个绑定项的内容时,DataGridRow和RowDetailsTemplate中的更改都会更新。例如

Items[i].Name = "new name";  // RowDetailsTemplate gets updated
但是,如果我将其中一个项分配给一个全新的对象,DataGridRow将更新,但RowDetailsTemplate不会更新。例如

Items[i] = new Model {Name = "new name"};  // RowDetailsTemplate NOT updated
起初我唯一想到的是,我需要向绑定项的CollectionChanged事件添加一个侦听器,并显式地发出属性更改通知。例如

Items = new ObeservableCollection<Model>();
Items.CollectionChanged += (o,e) => OnNotifyPropertyChanged("Items");
(Oh和模型类当然实现了
INotifyPropertyChanged

似乎这可能是我需要刷新details视图的DataContext的问题

为什么你不能:

Items.RemoveAt(i);
Items.Insert(i,(new Model {Name = "new name"});

也会有同样的效果

我不得不在CellEditEnding处理程序代码中插入这样一个肮脏的黑客:

DataTemplate temp = ProfileDataGrid.RowDetailsTemplate;
ProfileDataGrid.RowDetailsTemplate = null;
ProfileDataGrid.RowDetailsTemplate = temp;

行详细信息是更新的,但我也想知道masters是如何更新行详细信息的。

正如我所说,问题不在于更新良好的
DataGridRow
。它与
行详细信息模板
在一起。我现在就知道了。谢谢我正在做一些研究。我现在正在使用一个类似的解决方法——但这只是一个笨拙的解决方法,需要以一种适应视图特定行为的方式对viewmodel进行编码。我并不是真的在寻找一个解决方法——问题是真正试图找到问题的根源。当然。这看起来像是.NET实现的问题。不幸的是,我不知道答案。我会从查看.NET IL开始。谢谢,我会继续挖掘。:)在.NET4.6上有这个问题,所以它仍然是个问题。解决方法(删除,然后插入)为我解决了这个问题,但我不喜欢它。。。
Items.RemoveAt(i);
Items.Insert(i,(new Model {Name = "new name"});
DataTemplate temp = ProfileDataGrid.RowDetailsTemplate;
ProfileDataGrid.RowDetailsTemplate = null;
ProfileDataGrid.RowDetailsTemplate = temp;