각 트리보기 항목에는 하위 트리가 있습니다. 각 트리보기 항목의 하위 항목을 ObservableCollection에 바인딩하면 BackGroundWorker 또는 다른 스레드에서 항목을 추가 할 수 있습니다. 후속 컬렉션을 사용하여 트리보기 항목 하위를 바인딩하는 경우 백그라운드에서 하위보기로 자식을 추가 할 수 있습니다.
Simplifying the WPF TreeView by Using the ViewModel Pattern
Custom TreeView Layout in WPF
희망이 유용 할 것이다 : 또한
public class ThreadSafeObservableCollection<T> : ObservableCollection<T>
{
private SynchronizationContext SynchronizationContext;
public ThreadSafeObservableCollection()
{
SynchronizationContext = SynchronizationContext.Current;
// current synchronization context will be null if we're not in UI Thread
if (SynchronizationContext == null)
throw new InvalidOperationException("This collection must be instantiated from UI Thread, if not, you have to pass SynchronizationContext to con structor.");
}
public ThreadSafeObservableCollection(SynchronizationContext synchronizationContext)
{
if (synchronizationContext == null)
throw new ArgumentNullException("synchronizationContext");
this.SynchronizationContext = synchronizationContext;
}
protected override void ClearItems()
{
this.SynchronizationContext.Send(new SendOrPostCallback((param) => base.ClearItems()), null);
}
protected override void InsertItem(int index, T item)
{
this.SynchronizationContext.Send(new SendOrPostCallback((param) => base.InsertItem(index, item)), null);
}
protected override void RemoveItem(int index)
{
this.SynchronizationContext.Send(new SendOrPostCallback((param) => base.RemoveItem(index)), null);
}
protected override void SetItem(int index, T item)
{
this.SynchronizationContext.Send(new SendOrPostCallback((param) => base.SetItem(index, item)), null);
}
protected override void MoveItem(int oldIndex, int newIndex)
{
this.SynchronizationContext.Send(new SendOrPostCallback((param) => base.MoveItem(oldIndex, newIndex)), null);
}
}
나는이 기사가 당신에게 유용해야한다고 생각 : 그것은보기에 항목을 추가 동기화 컨텍스트를 사용 당신을 위해 ...
왜 Windows의 Invoke 메서드를 사용하지 마십시오 컨트롤 클래스 –