I have a wpf project, and I am trying to do a popup style window which is a separate wpf window I wrote. I am trying to do a simple Showdialog as I have done before on several other projects. I simply do the following from the MainWindow.xaml.cs
PopupWindow myPopup = new PopupWindow();
myPopup.ShowDialog()
At the PopupWindow() constructor I get an
The calling thread must be STA, because many UI components require this
Exception. I googled around, I think I understand the usual cause for the exception, I also saw the possible solutions.
- Add the STAThread property to the Main. Well its a WPF project, it should be generated as STAThread, and I also see in the generated Main that indeed it is.
- Launch the new window in a separate thread. I don't want to do that, I want this window to block the current Thread, and return the choice the user made on the window for the further run.
The original project was not created by me, I had to take it over from a colleague who left since. I can imagine that he did something nasty by creating the project and there are some setting wrong and that's why the main window is not the STAThread. I have however no idea what these setting could be and where I could start to look for them.
Have any of you seen this problem? Can you help me finding why the mainwindoe is not the STAThread?