通知 WPF DataGrid 有关更改
我有一个绑定到ICollectionView
的DataGrid
(启用了过滤器)。更具体地说,我设置了 view.Filter = SomeFilteringFunction
,它使用 public DateTime DateFrom { get... set... }
属性,也绑定到 DatePicker
。
好吧,现在,当我更改 DatePicker
时,绑定属性 DateFrom
已正确更改,但 DataGrid 并未明显重新过滤。
通知 DataGrid 更新自身的最正确方法是什么?
先感谢您!
詹姆斯
I have a DataGrid
bound to the ICollectionView
(with filter on). More specifically, I have set view.Filter = SomeFilteringFunction
which uses public DateTime DateFrom { get... set... }
property, also bound to the DatePicker
.
Well, and now, when I change DatePicker
, bound property DateFrom
is correctly changed but the DataGrid is not obviously re-filtered.
What is the most right way how to notify DataGrid
to update itself?
Thank you in advance!
James
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不应直接绑定到 ICollectionView,而应绑定到源集合,然后将筛选器应用到由 CollectionViewSource.GetDefaultView 返回的 ICollectionView。
然后,当 DatePicker 的值发生更改时,您需要告诉 ICollectionView 进行更新。
You shouldn't be binding directly to the ICollectionView, rather you bind to the source collection, and then apply the filter to the ICollectionView returned by CollectionViewSource.GetDefaultView.
Then when the value of the DatePicker changes you need to tell the ICollectionView to update.
您可以订阅
PropertyChanged
事件(我假设您在类上实现了该事件)并刷新处理程序中的视图:虽然不确定是否有更干净的方法,但我非常肯定您需要在某一时刻进行
Refresh
调用。You can subscribe to the
PropertyChanged
event (which i assume you implemented on the class) and refresh the view in the handler:Not sure if there is a cleaner way, though, but i'm quite positive you need to make that
Refresh
call at one point.