I need to integrate the WPF interface into a .NET 2.0 application.
The ObservableCollection needs to be changed in the GUI manager thread, so I came up with a solution that included InvokeLater()
ObservableCollection<Item> items;
public delegate void AddItemDelegate(Item i);
public void AddItem(Item item)
{
System.Windows.Application.Current.Dispatcher.BeginInvoke(
new AddItemsDelegate(i => items.Add(i), item);
}
However, since the project was originally written with .NET 2.0, the main thread uses it System.Windows.Forms.Application, therefore System.Windows.Application.Currentit is null.
I cannot just replace the current one System.Windows.Forms.Applicationwith System.Windows.Application, since my application relies heavily on this API, and the two classes are widely incompatible.
Is there any way to get current System.Windows.Application? Or a way to call BeginInvoke()on mine System.Windows.Forms.Application? Or do I think I wrote my own DIY system to delegate the publication of a collection from the right stream?