谓词
我有一个 TagTypeController 类,它为 WPF UserControl 的控制器提供集合视图,该控制器保存对集合视图的私有引用。
_ttController = new TagTypeController(_isProd);
CollectionView tagTypeList = _ttController.getTagTypes();
在 TagTypeController 中,创建 CollectionView 时,我设置过滤器委托,
if (_tagTypeList == null)
_tagTypeList = new CollectionView(CollectionViewSource.GetDefaultView(_tagTypeTable));
_tagTypeList.Filter = new Predicate<object>(filterTagTypes);
我想在 TagTypeController 类中找到该 collectionview 的所有过滤逻辑等。问题是,当 UserControl 的 TextBox 中的文本发生更改时,我通过委托给 UserControl 的控制器来响应该事件。当我要求刷新 tagTypeList 时,它不会调用 filterTagTypes 方法。是否不可能将过滤器委托放在不同的类中?
谢谢。
编辑:添加请求的代码
//parse the string to get just the portion after the last comma and space
Int32 _lastComma = _tempText.LastIndexOf(",");
_ttController.searchText = _tempText.Substring(_lastComma + 1).Trim();
tagTypeList.Refresh();
I have a TagTypeController class that provides a collection view to a controller for a WPF UserControl, which holds a private reference to the collection view.
_ttController = new TagTypeController(_isProd);
CollectionView tagTypeList = _ttController.getTagTypes();
In the TagTypeController, when creating the CollectionView, I'm setting the filter delegate
if (_tagTypeList == null)
_tagTypeList = new CollectionView(CollectionViewSource.GetDefaultView(_tagTypeTable));
_tagTypeList.Filter = new Predicate<object>(filterTagTypes);
I would like to locate all the logic for filtering, etc. of that collectionview in the TagTypeController class. The problem is, when the text changes in the TextBox of the UserControl, I'm responding to that event by delegating to the controller for the UserControl. When I ask the tagTypeList to refresh, it does not call the filterTagTypes method. Is it not possible to have the filter delegate in a different class?
Thanks.
EDIT: adding requested code
//parse the string to get just the portion after the last comma and space
Int32 _lastComma = _tempText.LastIndexOf(",");
_ttController.searchText = _tempText.Substring(_lastComma + 1).Trim();
tagTypeList.Refresh();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为问题可能是您使用的是过滤谓词而不是事件。如果您查看 CollectionView 文档它说:
因此,您不想设置属性,而是使用事件处理程序,因此代码看起来像
FilterTagTypesHandler
的定义类似另一种可能性是您正在创建一个新的
CollectionView
转换GetDefaultView()
的结果。当您这样做时,您可能会失去与控件的连接。如果您查看 CollectionViewSource 的文档推荐的使用方式是I think the problem might be that you are using the filter predicate rather than the event. If you look at the CollectionView documentation it says:
So instead of setting the property you want to use the event handler so the code would look like
where
FilterTagTypesHandler
is defined likeThe other possibility is that you are creating a new
CollectionView
instead of casting the result ofGetDefaultView()
. You are probably losing your connection to the control when you do that. If you look at the CollectionViewSource's documentation the reccommend way of using it is