ICollectionView.filter WPF с большими наборами данных

Вот пример того, как справиться с этим! Вам необходимо получить доступ к форме через this.outerForm.

Если вы используете VS Code (или другую хорошую IDE-ориентированную на Typescript), она предложит вам доступные методы при вводе. В этом примере я устанавливаю crqNumber как required.

this.outerForm.controls.secondFormGroup.controls.crqNumber
  .setValidators(Validators.compose([Validators.required]));
24
задан J W 12 May 2009 в 07:59
поделиться

2 ответа

Pay close attention to your filter function. Make sure you aren't doing any unnecessary boxing/unboxing and you aren't doing extensive calculations in it. You should also pay attention to which kind of CollectionView you're using, some are faster than others. From Bea's post on sorting:

  • A CollectionView is created if your source implements IEnumerable. If the source implements IEnumerable only, you will not be able to sort or group the collection (you can only filter it). Also, perf will not be the best if the source has a large number of items or if you perform dynamic operations such as insertions and deletions. If this is your scenario, you should consider having your source implement a stronger interface. ICollection is slightly better because it provides a Count property.

  • ListCollectionView is the view type created when the source implements IList. Compared to IEnumerable and ICollection, IList performs much better for large or dynamic lists because it provides an indexer, allowing us quick random access. In addition, IList allows sorting, grouping and filtering. But ideally your source collection derives from ObservableCollection, the mother of all collections in the eyes of data binding, since it provides several extra goodies such as property and collection change notifications.

  • BindingListCollectionView is the type of view created by Avalon when the source collection implements IBindingList. This is the view we deal with in the ADO.NET scenario. It supports sorting and grouping, but not traditional filtering. Instead, it has an additional CustomFilter property that delegates filtering to the DataView (see my post on ADO.NET for more details).

You can kick the filtering to a different thread as @mihi said but I have used CollectionViews to run multiple filters concurrently on an ObservableCollection with 50,000 items on an object with ~60 variables (columns in a database table) without noticeable lag.

One thing I notice immediately in your filter function is the input is of type Object which likely means you're doing a type conversion within the function and may not need to. You also use Predicate which doesn't include a return type so that probably requires some type conversions or reflection within the CollectionView's filtering methods and might slow you down as well.

21
ответ дан 29 November 2019 в 00:15
поделиться

Рассматривали ли вы фильтрацию в другом потоке или с помощью диспетчера?

WPF Threads: создание более отзывчивых приложений с помощью диспетчера дает вам хороший обзор некоторых доступных вам параметров потоковой передачи.

3
ответ дан 29 November 2019 в 00:15
поделиться
Другие вопросы по тегам:

Похожие вопросы: