I have just made a simple Console Application and i would like to open WPF window now. I added WPF item to my Application :P. But i have no idea how to Open this window from my Main(). I hope some1 can help me :).
Asked
Active
Viewed 1.8k times
6
-
3[Here](http://stackoverflow.com/questions/8047610/re-open-wpf-window-from-a-console-application) [Here](http://stackoverflow.com/questions/4509714/how-to-start-the-wpf-window-from-console-programmatically) [Here](http://social.msdn.microsoft.com/Forums/vstudio/en-US/dbc8b14c-d523-4237-997a-c55588f04c2c/calling-a-wpf-control-from-a-console-application?forum=wpf) – Jonesopolis Oct 11 '13 at 17:50
1 Answers
13
Application app = new Application();
app.Run(new Window1());

Daniel
- 10,864
- 22
- 84
- 115
-
I hope that Window1() is a WPF's name? It simply doesnt work for me i have tried almost every single combination. `var app = new Application(); app.Run(new UserControl1()); //UserControl1 is my WPF's window name` And here's my WPF's code: `public partial class UserControl1 { public UserControl1() { InitializeComponent(); } private void Button_Click(object sender, RoutedEventArgs e) { MessageBox.Show("Test"); } }` – user2871989 Oct 11 '13 at 18:18
-
-
1I was trying to resolve this problem. But i am still stuck. I managed to make this---> `[STAThread] static void Main(string[] args) { var app = new Application(); app.Run(new Window()); }` a new window will appear. But my WPF's Window is already there and i just want to Initialize it from Main() ;/. i am confused – user2871989 Oct 11 '13 at 18:47
-
@user2871989 Dont use `new Window()`. you have to create a new Window, like you have created a new UserControl. It should be like `public partial class MyWindow : Window`. The contents of your `UserControl` should be on that window, rather than the usercontrol (or you could place the usercontrol on the window). – Daniel Oct 11 '13 at 18:53