CollectionViewSourceを使用している場合、バックグラウンドワーカーにデータをロードするにはどうすればよいですか?私のCollectionViewSourceがUIスレッドにあるので、エラーをスローします。BackgroundWorkerとCollectionViewSource
これは私のコード(XAMLで設定したマイバックグラウンドワーカー)のすべて:
public partial class DepartmentsLookup : Window
{
private BackgroundWorker backgroundWorker;
private ObservableCollection<Department> AllDepartmentsData;
private ListCollectionView AllDepartmentsView;
private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
{
IEnumerable<Department> data = null;
using (ArchiveEntities db = new ArchiveEntities())
{
data = db.Departments;
this.AllDepartmentsData = new ObservableCollection<Department>(data);
}
CollectionViewSource departmentsSource = (CollectionViewSource)this.FindResource("AllDepartmentsDataSource");
departmentsSource.Source = this.AllDepartmentsData;
this.AllDepartmentsView = (ListCollectionView)departmentsSource.View;
}
public DepartmentsLookup()
{
InitializeComponent();
backgroundWorker = ((BackgroundWorker)this.FindResource("backgroundWorker"));
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
backgroundWorker.RunWorkerAsync();
}
}
ありがとう。
私は背景職人を見ません。それにもかかわらず、コレクションビューを設定するときにディスパッチャを使用する必要があります – blindmeis
例外と例外はどこにスローされますか? –
私の質問が更新されます。 –