PagedCollectionView 将 ObservableCollection 包装在 DataGrid 中时会在不存在数据时清除列标题
我正在使用 PagedCollectionView 进行分组。我有一个数据网格和一个带有搜索按钮的文本框。网格的 ItemSource 是我的 PagedCollectionView,PagedCollectionView 包装了一个 ObservableCollection,因为网格中的项目可以通过后台进程更新其绑定对象。当您单击搜索时,我首先通过 ObservableCollection 进行清除,然后使用数据库中的数据加载它。当我清除我的集合时,DataGrid 上的内容就会消失,包括列。当物品添加到我的收藏中时,它们会重新出现。我真的很希望保留这些列及其标题,因为当它们消失时,它会非常不和谐,更不用说排序顺序等都会丢失。我相信这些项目会立即消失,因为它是一个 ObservableCollection,但我需要它,以便可以通过上述后台进程更新行。如果我删除 PagedCollectionView 作为包装器并简单地将 DataGrid 的 ItemSource 设置为 ObservableCollection,则不会发生任何此行为,即使清除集合,我的列和标题也会保留,并且我的行会通过后台进程即时更新。还有其他人观察过这种行为吗?有谁知道有什么解决方法吗?或者我只是做错了什么?
I am using the PagedCollectionView for grouping. I have a DataGrid and a textbox with a search button. The ItemSource of the grid is my PagedCollectionView, and the PagedCollectionView wraps an ObservableCollection because items in the grid can have their bound objects updated by a background process. When you click search, I first clear by ObservableCollection then load it with data from a db. The moment I call clear on my collection, the contents on of the DataGrid disappear, INCLUDING THE COLUMNS. They reappear when items are added to my collection. I would really like the columns and their headers to remain, as when they disappear it is quite jarring, not to mention sort orders, etc are lost. I believe the items disappear instantaneously because it is an ObservableCollection, but I need it to be so that the rows can be updated by the aforementioned background process. If I remove the PagedCollectionView as a wrapper and simply set the ItemSource of the DataGrid to the ObservableCollection, none of this behavior occurs, my columns and headers persist even when the collection is cleared, and my rows update instantaneously by the background process. Has anyone else observed this behavior? Does anyone know any workarounds? Or am I just doing something wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
出现问题是因为我使用自动生成的列。每次我清除集合时,PageCollectionView 都会为我重新生成列。通过关闭该属性并使用 Blend 为我“预生成”列,我能够解决这个问题。
The problem occurred because I was using AutoGenerated columns. Everytime I cleared my collection the PageCollectionView regenerated the columns for me. By turning that property off and using Blend to "pre-generate" the columns for me, I was able to get around the issue.