在 WPF 中创建视图的视图
好的,所以我需要从现有的 ICollectionView
创建一个 ICollectionView
。 我的想法是,我可以采用在现有视图上设置的任何过滤器/分组/排序,然后从该“基本”视图创建其他视图,实际上“分层”或聚合我的过滤器等。
我需要最终视图当源集合(ObservableCollection
)更新以及数据项更新时,“自动”神奇地更新其项,例如调用 Refresh()
方法。我需要避免对所有视图调用 Refresh,因为我们不知道原始集合和最终视图之间的所有视图,并且 Refresh()
非常慢。
我们试图避免滚动我们自己的视图类——我们更愿意(强烈)使用 .net 库中已经存在的东西。
更新
我们就此问题致电 Microsoft。我知道其他人也有同样的问题,至少,博士。 WPF 告诉我。
OK, so I need to create an ICollectionView
from an existing ICollectionView
.
The idea is that I can take whatever filters/grouping/sorting has been set on the existing view and then create other views from that "base" view, in effect "layering" or aggregating my filters, etc.
I need the end view to update its items "auto-magically" when the source collection (an ObservableCollection<T>
) updates and when the data item is updated--like calling the Refresh()
method. I need to avoid calling Refresh on all the views because we don't know all the views between the original collection and the end view, and the Refresh()
is painfully slow.
We are trying to avoid rolling our own view classes--we would prefer (strongly) to use something that already exists in the .net library.
Update
We have a call in to Microsoft about this. I know others have the same problem, as least, that what Dr. WPF tells me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,我们最终推出了自己的集合和视图。
我们的集合基于 ObservableCollection,它附加到集合中每个元素的 PropertyChanged 事件。我们有一个事件,每当属性更改时我们都会调用该事件,这样其他类和/或视图就可以挂钩该事件并按照他们认为合适的方式处理它。
然后我们基于 ListCollectionView 创建了自己的 ICollectionView。该视图监视集合中的 CollectionItemChanged 事件,并简单地调用(如果集合中的项目是 IEditableObject)IEditableList.EditItem(...) 和 IEditableList.CommitItem(...)
此 Edit() ,然后 CommitItem() 会导致视图刷新而不实际调用 Refresh()
这完全是“haxor”,但是,它一直有效,直到 MS 为我们可怜的开发人员做一些事情来解决这个问题。
OK, so we ended up rolling our own collection and view.
Our collection is based from ObservableCollection which attaches to the PropertyChanged event of every element that is in the collection. We have an event that we invoke whenever the property changes, this way other classes and/or views can hook that and handle it as they see fit.
We then created our own ICollectionView based from ListCollectionView. The view watches for the CollectionItemChanged event from the collection and simply calls (if the item in collection is IEditableObject) IEditableList.EditItem(...) and IEditableList.CommitItem(...)
this Edit() and then CommitItem() causes the view to refresh without actually calling Refresh()
This is totally "haxor" but, it works until the day MS does something for us poor developers to fix this.