我有一个IcollectionView名为的属性Suggestions,它绑定到 ListBox 的ItemsSource.
我使用以下代码进行设置
// Set up Suggestions collection for filtering purposes
var collectionViewSource = new CollectionViewSource();
collectionViewSource.Source = SomeCollection; // SomeCollection is of type IEnumerable!!
// Create view
Suggestions = collectionViewSource.View;
Suggestions.Filter = new Predicate<object>(
item =>
item.ToString().StartsWith(SearchString, true, CultureInfo.CurrentCulture))
SearchString绑定到 TextBox 的Text属性,每当更改触发重新Suggestions.Refresh()过滤集合时。
这很好用,但会显示所有可用的项目。我怎样才能让它只显示前 X 项?