UI のリスト コントロールにバインドされたObservableCollection
プロパティがあります。ViewModel
ItemSource
実行時に List Control に表示されるアイテムの数を更新するために、 のObservableCollection
プロパティにアイテムを追加していますViewModel
。以下で共有する 2 つの異なるタイプのコード スニペットを使用しましたが、リスト コントロールに更新されたデータを反映するのに非常に時間がかかります。
コード スニペット 1:
public void AddRange(IEnumerable<T> items)
{
foreach (var item in items)
{
this.Items.Add(item);
}
}
コード スニペット 2:
void BatchAddPeople(IEnumerable<Person> newPeople)
{
var currentPeople = _people;
// stop WPF from listening to the changes that we're about
// to perform
this.People = null;
// change
foreach (var person in newPeople)
{
currentPeople.Add(person);
}
// cause WPF to rebind--but only once instead of once for
// each person
this.People = currentPeople; //Updating the ObservableCollection property with complete list
}
メソッド内のコードBackGroundWorker
を更新するスレッドを使用してこれらの両方のアプローチを試しましたが、それでもパフォーマンスの問題に直面しています。ObservableCollection
Dispatcher.Invoke
この場合、パフォーマンスへの影響を減らす方法について何か考えがありますか?