0

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();

iis express 7.5 roaming profile visual studio 2010 sp1

Unless I redirect the My Documents folder to a local copy IIS Express fails to start with the following error message: Filename: redirection.config Error: Cannot read configuration file

This happens when starting a new web project from studio or even is I just double click on the iisexpress.exe file.

Any way around this or must I continue to redirec the My Documents folder

4

1 回答 1

1

我认为问题可能是您使用的是过滤谓词而不是事件。如果您查看CollectionView文档,它会说:

如果您的视图对象来自 CollectionViewSource 对象,您可以通过为 Filter 事件设置事件处理程序来应用过滤逻辑。

因此,您不想设置属性,而是使用事件处理程序,因此代码看起来像

_tagTypeList.Filter += FilterTagTypesHandler;

其中FilterTagTypesHandler定义为

private void FilterTagTypesHandler(object sender, FilterEventArgs e){
  //do filtering
}

另一种可能性是您正在创建一个新CollectionView的而不是转换GetDefaultView(). 当您这样做时,您可能会失去与控件的连接。如果您查看CollectionViewSource 的文档,推荐使用它的方式是

myCollectionView = (CollectionView)
    CollectionViewSource.GetDefaultView(rootElem.DataContext);
于 2011-05-02T22:27:08.393 回答