I have a WinForms application that acts as a service(so no actual UI), but it is a WinForms application.
In this application I a form that has an ElementHost and in the elementHost I have a WPF grid.
In one of my classes I have this code:
Dim frm1 As New frmHostWpfGrid '->HERE I get the error
frm1.WpfGrid.WpfGridControl.BeginDataUpdate()
frm1.WpfGrid.WpfGridControl.ItemsSource = Nothing
frm1.WpfGrid.WpfGridControl.RestoreLayoutFromStream(LayoutStream)
frm1.WpfGrid.WpfGridControl.ItemsSource = mdtData
frm1.WpfGrid.WpfGridControl.EndDataUpdate()
THe error I get is:
The calling thread must be STA, because many UI components require this.
When I tried with a WinForms form and a grid I didn't have this problem.
PS1. Notice that I don't want to show the form
PS2. I tried to fill directly a WPF grid without a form and I got the same error