收集过滤器转换类型错误
本文关键字:类型 错误 转换 过滤器 | 更新日期: 2023-09-27 18:18:50
我已经过滤了我的集合
这是我的代码
public ICollectionView LogEntriesStoreView { get; set; }
var collection = new ObservableCollection<Service>(this._model.GetService());
this.LogEntriesStoreView = CollectionViewSource.GetDefaultView(collection);
this.LogEntriesStoreView.Filter += new FilterEventHandler(ShowOnlyBargainsFilter);
private void ShowOnlyBargainsFilter(object sender, FilterEventArgs e)
{
AuctionItem product = e.Item as AuctionItem;
if (product != null)
{
// Filter out products with price 25 or above
if (product.CurrentPrice < 25)
{
e.Accepted = true;
}
else
{
e.Accepted = false;
}
}
}
现在我得到这个错误隐式类型转换"System.Windows.Data. xml"。过滤EventHandler" in "系统。谓词"不能是
this._view = new TViewType();
this._model = new ServiceModel();
this.Service = new ObservableCollection<Service>(this._model.GetService());
this.OkCommand = new RelayCommand(o => this.OKRun());
this.LostFocusCommand = new RelayCommand(o => this.LostFocusOKRun());
// в переменную получаем нашу коллекцию
var collection = new ObservableCollection<Service>(this._model.GetService());
// инициализируем поле типа ICollectionView нашей коллецией
this.LogEntriesStoreView = CollectionViewSource.GetDefaultView(collection);
this.LogEntriesStoreView.Filter = new Predicate<object>(Contains);
this.LogEntriesStoreView.Filter += new FilterEventHandler(ShowOnlyBargainsFilter);
this._view.SetDataContext(this);
this._view.ShowIView();
}
private void OKRun()
{
MessageBox.Show("One Click");
}
private void LostFocusOKRun()
{
MessageBox.Show("LostFocus");
}
private void TextChanged()
{
}
private void ShowOnlyBargainsFilter(object sender, FilterEventArgs e)
{
}
public bool Contains(object de)
{
return true;
}
完整代码,我在我的代码中添加了一个谓词。例如在msdn
EventHandler应该为CollectionViewSource LogEntriesStoreView
工作。
CollectionView和CollectionViewSource的Filter实现是有区别的。
https://msdn.microsoft.com/en-us/library/system.windows.data.collectionview.filter (v = vs.110) . aspx
https://msdn.microsoft.com/en-us/library/system.windows.data.collectionviewsource.filter (v = vs.110) . aspx