I have WinForms with WPF UserControl.
public partial class DynamicMediator : Form
{
public DynamicMediator()
{
InitializeComponent();
lmDynamicMediator = new LMDynamicMediator.MediatorMainWindow();
this.elementHost1.Child = this.lmDynamicMediator;
}
public MainWindowViewModel GetEditFormViewModel()
{
return lmDynamicMediator.Resources["ViewModel"] as MainWindowViewModel;
}
}
I start a new process in my ViewModel after that I need to update my observableCollection in ViewModel I use
Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => HasListMessages.Add(item)));
but I have exception like this
This type of CollectionView does not support changes to its SourceCollection from a thread different from the Dispatcher thread
if I use code like this
Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() => HasListMessages.Add(item)));
I have exception like this
System.Windows.Application.Current.get returned null
What I do wrong?
How I can get System.Windows.Application.Current in my ViwModel