WPF DataGrid CanUserAddRows到ObservableCollection

WPF DataGrid CanUserAddRows into ObservableCollection
2021-03-07
  •  译文(汉语)
  •  原文(英语)

在Datagrid上,我将CanUserAddRows设置为true,但是,当我确实通过网格添加行时,是否有可以触发的事件,所以我可以看到实际上正在添加ObservableCollection吗?

我说这种逻辑是因为当用户从网格中添加一行时,基础设施库会触发事件

干杯

速聊1:
抱歉,您使用基础设施还是MS?
速聊2:
我在WinForms中使用了Infragistics,但是在WPF中,我正在检查MS Grid是否与Infragistics中的WinGrid一样好.
解决过程1

尝试DataGrid.LoadingRow事件

或者您实际上可以处理ObservableCollection.CollectionChanged / PropertyChanged

速聊1:
谢谢,可以将此事件添加到视图中,而不是ViewModel吗?我想尝试通过ViewModel将其添加到集合中,如果无法做到这一点,我将很乐意通过视图进行添加.谢谢
速聊2:
LoaingRow事件是由DataGrid公开的,因此是View.您是否要在UI中添加一行,看看绑定到DataGrid.ItemSource的基础集合是否已更新?抱歉,我没有尝试过这种情况.AFAIK,添加DataGridRow时会触发LoaingRow事件,它也可以在虚拟化模式下工作.我认为您可以简单地放弃它,看看它是否满足您的需求.干杯.

On a Datagrid I have CanUserAddRows set to be true, however, when I do add a row via the grid is there an event that can be fired so I can see that the ObservableCollection is actually being added?

I say this logic as the infragistics library fires an event when a user adds a row from the grid

Cheers

Talk1:
Sorry, do you use infragistics or the MS one?
Talk2:
I have used Infragistics in WinForms, but in WPF I am checking to see if the MS Grid is as good as the WinGrid in Infragistics.
Solutions1

Try the DataGrid.LoadingRow Event

Or you could actually handle the ObservableCollection.CollectionChanged/PropertyChanged

Talk1:
Thanks, will this event be added to the view though and not the ViewModel? I want to try to add to the collection via he ViewModel, if this cannot be done, I will be happy to do via the view. Thanks
Talk2:
The LoaingRow event is exposed by the DataGrid, so the View. Do you mean to add a row in UI and see if the underlying collection bound to the DataGrid.ItemSource is updated? Sorry, I haven't tried this case. AFAIK, the LoaingRow event fires when a DataGridRow is added, it works in virtualisation mode too. I think you could simply give it go and see if it meets your need. Cheers.
转载于:https://stackoverflow.com/questions/23053726/wpf-datagrid-canuseraddrows-into-observablecollection

本人是.net程序员,因为英语不行,使用工具翻译,希望对有需要的人有所帮助
如果本文质量不好,还请谅解,毕竟这些操作还是比较费时的,英语较好的可以看原文

留言回复
我们只提供高质量资源,素材,源码,坚持 下了就能用 原则,让客户花了钱觉得值
上班时间 : 周一至周五9:00-17:30 期待您的加入