I have a WPF UserControl
that is being tested in both a WPF
app and WinForms
app. The control is made up of other controls, mainly a map control. Work is done inside the UserControl
using Tasks
and doing work on the map control by using Application.Current.Dispatcher.Invoke
.
Everything works fine when hosting this control in a WPF app, but in the WinForms
app, a NullReference exception is thrown anytime the Dispatcher.Invoke
is used. In fact, Application.Current
is always null in the WinForms app.
I've seen this: https://stackoverflow.com/a/14753962/2480598 which suggests:
if ( null == System.Windows.Application.Current )
{
new System.Windows.Application();
}
But what if I don't have control over the WinForms
app? Is there no other way to handle this?