tags:

views:

871

answers:

4

I recently started a C# project (VS 2008) as a 'Console' project where I wrote a few libraries, test programs, etc. Now I'd like to add a couple of WPF windows, but it looks like console project won't let me do that. I'm coming from Java so this is a little strange. How can I add a WPF form (which I will instantiate my self from my "main" class?

A: 

Are you sure you need Console project? You can create 'WPF application' project and add references to your libraries, etc. If try to show WPF window from console app you will gen an exception due to differences in threading model between Console & WPF apps.

aku
[STAThread] attribute for Main method makes it possible !
Kushal Waikar
+1  A: 

You should move your library code to some other "Class library" project and use it from your Console project. Your WPF windows should be in another "WPF application" project which will also reference your "Class library".

Dmitriy Matveev
A: 

Thanks to aku and Dmitriy, I create another project (WPF) which will reference my console based code.

Shahbaz
+6  A: 

The accepted answer is not entirely true, I'm afraid, just add the [STAThread] attribute before your mainmethod and make references to the right libraries (like System.Windows) and you're all set to add wpf windows. It's even easy!

http://windows-presentation-foundation.com/WPF_From_Scratch.aspx

Peter
You are right Peter!
Kushal Waikar