The problem is that the
PresentationFramework.dll
assembly isn't in a directory that's in the compiler's search path. Instead, it's in a sub-directory called "WPF" under the main framework directory:
parameters.ReferencedAssemblies.Add("WPF\\PresentationFramework.dll");
You'll also need some other references:
parameters.ReferencedAssemblies.Add("System.Xaml.dll");
parameters.ReferencedAssemblies.Add("WPF\\WindowsBase.dll");
parameters.ReferencedAssemblies.Add("WPF\\PresentationCore.dll");
You'll also need to correct the case of the
MessageBox
class in your code to compile.
With those changes in place, you'll then find a single compiler error:
The name 'InitializeComponent' does not exist in the current context
That's because your compilation unit doesn't include any of the artefacts that Visual Studio generates for you when you create a new WPF window, including the BAML
(compiled XAML) and the other part of the partial class.
If you look at an existing WPF project in Windows Explorer, you'll see a folder called
obj
. Under that, in a folder with the same name as the configuration
(typically Debug
or Release
), you'll see that each WPF window has three compiler-generated files:
WindowName.baml
- the compiled version of the XAML markup;WindowName.g.cs
- defines the fields, the InitializeComponent
method to load the BAML from the embedded resources, and code to connect the fields to the loaded BAML;WindowName.g.i.cs
- seems to be a duplicate of .g.cs
, possibly used for Intellisense;
Since you're generating the code manually, you'll need to duplicate these artefacts somehow, or move the code from the
.g.cs
file into your main class.