C# ICollection筛选器错误转换类型
我已经过滤了我的收藏 这是我的密码C# ICollection筛选器错误转换类型,c#,wpf,mvvm,C#,Wpf,Mvvm,我已经过滤了我的收藏 这是我的密码 public ICollectionView LogEntriesStoreView { get; set; } var collection = new ObservableCollection<Service>(this._model.GetService()); this.LogEntriesStoreView = CollectionViewSource.GetDefaultView(collection);
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.Predicate中的隐式类型转换System.Windows.Data.Filter EventHandler不能为空
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上生成的所有事件处理程序都应适用于CollectionViewSource LogEntriessStoreView CollectionView和CollectionViewSource的过滤器实现之间存在差异
我理解它,但我做的每件事都是举例说明,一定是一些语法错误导致了这一点。您能在这里添加相关代码吗?您是否遵循了每个步骤?检查是否已分配类似于myCollectionView.Filter=new PredicateContains;的内容;。