如何根据ICollectionView过滤结果更新UI?
我有两个控件 - SearchFilter
和 SearchResult
。过滤器包含带有过滤结果命令的按钮。结果控件有一个 ListView
,它绑定到 ICollectionView
属性。
<ListView ItemsSource="{Binding SearchList}">
我的带有过滤器逻辑的模型视图:
private void FilterTheResults()
{
var list = (ListCollectionView) SearchList;
list.Filter = x => ((SearchItem)x).Type == "Video";
}
问题如下:
如果我将带有命令的按钮从筛选器控件移动到结果控件,则我的 UI 会在每次筛选器操作后更新。但我想把这些事情分开。我尝试在 FilterTheResults()
中使用 SearchList.Refresh()
和 PropertyChanged
但没有成功。
I have two controls - SearchFilter
and SearchResult
. Filter contains buttons with commands to filter results. Result control has a ListView
with a binding to ICollectionView
property.
<ListView ItemsSource="{Binding SearchList}">
my modelview with filter logic:
private void FilterTheResults()
{
var list = (ListCollectionView) SearchList;
list.Filter = x => ((SearchItem)x).Type == "Video";
}
The problem is as follows:
If I move buttons with commands from the filter control to the result one, my UI is updated after each filter action. But I want to keep these things separate. I have tried to use SearchList.Refresh()
and PropertyChanged
in FilterTheResults()
without success.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编者注:@Yevhen Martynov 编辑了他在问题中找到的答案。我把它放在这里作为答案。
解决方案是两个控件的视图模型的一个实例(通过
Window
的DataContext
)。Editor's note: @Yevhen Martynov edited the answer he found into his question. I put it here as an answer instead.
The solution is the one instance of viewmodel for both controls (through
DataContext
ofWindow
).