Create a WPF window from command prompt application
Is it possible to create WPF window from a command prompt application?
for example I have a MainWindow WPF class with contains the main windows of my application. when I use the following code in my command prompt application I get this error: "The calling thread must be STA".
class Program
{
static void Main(string[] args)
{
MainWindow main = MainWindow();
开发者_StackOverflow中文版 main.Show();
}
}
I really need to create the window in my command prompt application but i don't know if its possible. please guide me how to do this.
regards
You can correct that error by marking the Main method with a STAThreadAttribute. You will also need to start a message pump by calling Application.Run. For example:
class Program
{
[STAThread]
static void Main(string[] args)
{
MainWindow main = new MainWindow();
main.Show();
new Application().Run();
}
}
精彩评论