WPF 不支持從調度程序線程以外的線程對其 SourceCollection 進行的更改
該問題出現在WPF中的VM類中,ObservableCollection類型,該類型的 CollectionView 不支持從調度程序線程以外的線程對其 SourceCollection 進行的更改,解決辦法:
ThreadPool.QueueUserWorkItem(delegate
{
SynchronizationContext.SetSynchronizationContext(new
DispatcherSynchronizationContext(System.Windows.Application.Current.Dispatcher));
SynchronizationContext.Current.Post(pl =>
{
//里面寫真正的業務內容
_FrameContents.Add(frame);
_DataGridMain.ScrollIntoView(_FrameContents[_FrameContents.Count - 1], _DataGridMain.Columns[0]);
}, null);
});
其中 _FrameContents 就是public ObservableCollection<FrameContent> _FrameContents 類型。
By:https://www.cnblogs.com/jiangyan219/articles/9248947.html

