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?
 
CuteBugConnect With a Mentor Commented:
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
 
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
CuteBugCommented:
PresentationFramework.dll
0
 
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
All Courses

From novice to tech pro — start learning today.