I have a style loaded wpf application and I need to create a separate UI thread for a window. The window uses styles that the rest of the application is using. The styles is in a resource xaml embedded in the solution. The window is created with code that looks like this.
Dim thread As New Thread(Sub()
Dim w As New TimelineSceneEd
w.Show()
System.Windows.Threading.Dispatcher.Run()
End Sub)
thread.SetApartmentState(ApartmentState.STA)
thread.Start()
When the window calls InitializeCompenent() I get the following exception
'Set property 'System.Windows.FrameworkElement.Style' threw an exception.' Line number '27' and line position '171'.
with the inner exception of:
{"The calling thread cannot access this object because a different thread owns it."}
My guess is that there is a generated class somewhere that is used to parse the xaml file containing the styles for the wpf program, and that this class is on the other main UI Thread. However if i run a dispatcher.invoke off to the main ui thread with initlializecompenent, I still get problems. Any ideas?
Of course I cannot look at any source code because this is framework code.