Simple WPF Window via C# command line compiler

In the code below I am trying to create a simple WPF Window through C# command line compiler. But the compiler points an error saying that the Controls doesn't not exist in the System.Windows namespace. The exact error message is:

WPF.cs(2,22): error CS0234: The type or namespace name 'Controls' does not exist
        in the namespace 'System.Windows' (are you missing an assembly
        reference?)
using System;
using System.Windows.Controls;

class Window1 : Window
{
}
class Program
{
    public static void Main()
    {
        Application.Run(new Window1());
    }
}

Open in new window

a_anis3000Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CuteBugCommented:
You need to add a reference to System.Windows.Controls in the command line compiler using the /reference: tag

Check this link
http://msdn.microsoft.com/en-us/library/ms379563%28VS.80%29.aspx
http://msmvps.com/blogs/luisabreu/archive/2007/08/31/compiling-c-code-from-de-code-line.aspx
0
a_anis3000Author Commented:
Any idea what is the name of the assembly reference file that contains the namespace I am after?
0
CuteBugCommented:
PresentationFramework.dll
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

a_anis3000Author Commented:
Ok.... seems to work now but I get another error message

WPF.cs(4,17): error CS0246: The type or namespace name 'Window' could not be
        found (are you missing a using directive or an assembly reference?)

0
CuteBugCommented:
Check this link
this gives the entire list of references you have to make

http://msdn.microsoft.com/en-us/library/aa970678.aspx
0
a_anis3000Author Commented:
well according to the link the presentationframework.dll, windowsbase.dll and presentationcore.dll are the entire reference list, so I tried to include all of them yet I still get the same error
0
CuteBugCommented:
add
using System.Windows;

in you WPF.cs file
0
a_anis3000Author Commented:
Ok... seems to be almost working now, except its giving me the following error

WPF.cs(12,9): error CS0120: An object reference is required for t
        field, method, or property
        'System.Windows.Application.Run(System.Windows.Window)'
0
CuteBugCommented:
Since you are trying to create a WPF Window entirely in code

you have to change your code to the code given below.

Also I suggest you use a IDE like Visual Studio to create WPF applications. It would be much more easier.

If you want a free tool, use kaxaml (http://www.kaxaml.com/)
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Markup;

public class Window1 : Window
{
  public Window1()
  {
  InitializeComponent();
  }
  private void InitializeComponent()
  {
    // Configure the form.
    this.Width = this.Height = 285;
    this.Left = this.Top = 100;
    this.Title = "My Window";
  }
}

public class Program : Application
{
  [STAThread()]
  static void Main()
  {
      Program app = new Program();
      app.MainWindow = new Window1();
      app.MainWindow.ShowDialog();
  }
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.