문제

나는있다 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 텍스트 상자에 묶여 있습니다 Text 속성, 변경 될 때마다 트리거가 발생합니다 Suggestions.Refresh() 그것은 컬렉션을 다시 시작합니다.

이것은 잘 작동하지만 사용 가능한 모든 항목을 보여줍니다. 상단 X 항목 만 표시하게하려면 어떻게해야합니까?

도움이 되었습니까?

해결책

필터 만 움직일 수 없습니다 Predicate 조건 SomeCollection.Where 절?:

SomeCollection = SomeCollection.Where(item => item.ToString().StartsWith(
    SearchString, true, CultureInfo.CurrentCulture)).Take(10);
collectionViewSource.Source = SomeCollection;

다른 팁

가시성을 모든 필터링 된 항목과 연관시키고 상위 X 항목에 대해서만 가시성을 true로 설정하거나,

먼저 모든 항목을 필터링하고 상단 X 항목을 다른 속성에 넣고 UI에 바인딩합니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top