ICollectionView.Refresh 不会重新过滤集合
我的视图模型中有 3 个级联的 ICollectionView
,其中一个依赖于另一个。 第一个不绑定到视图上的控件,而是用作即将作为主从细节向用户显示的两个即将出现的控件的关键过滤器。
我的问题是,我将一个过滤器谓词附加到主集合视图,但是当我从中调用 Refresh
时,它根本不会进入过滤器。我什至尝试从过滤器谓词中抛出异常,这样万一调试器无法到达该代码,我仍然会看到它到达,但没有抛出异常。
我调用 Refresh 但它没有将我带到过滤谓词 - 这意味着它没有重新创建视图,这可能是什么原因?
I have 3 cascading ICollectionView
s in my view model where one relies on the other.
The first one, isn't bound to a control on the view but is rather used as a key-filter for the two upcoming ones that are displayed to user as master-detail.
My problem is, I attached a filter predicate to the main collection-view, but when I call Refresh
from it, it doesn't go to the filter at all. I even tried throwing an exception from the filter predicate so in case the debugger cannot reach that code I will still see it arrived, but no exception was thrown.
What can be the reason that I call Refresh and it doesn't take me to the filter predicate - meaning it's not recreating the view?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了一个可行的解决方法,但我不喜欢它。
我正在做的是再次重置
Filter
属性,这样就可以完成任务。我在 Reflector 中徘徊了一会儿,试图找到我错过的东西,但没有成功地澄清其中的怪癖。
更新
我找到了一个更简单的解决方案。
我将第一个
ICollectionView
更改为简单的IEnumerable
,返回 Linq 查询。不知道刷新不起作用的原因,但是在其他集合视图(绑定到 UI)上,刷新确实起作用,因此
IEnumerable
的 linq 过滤器确实起作用工作。I found a workaround that works, but I don't like it.
What I'm doing is resetting the
Filter
property again, that does the job.I wandered around a bit in Reflector trying to find what am I missing but didn't have great success clarifying what's the quirk.
UPDATE
I've found a much simpler solution.
I changed the first
ICollectionView
to a simpleIEnumerable<Product>
, returning a Linq query.Without finding out why the refresh didn't work, however on the other collection views (that are bound to the UI) the refresh does work, and so, the linq filter of the
IEnumerable<Product>
does the job.