Understanding the problem… Why? When?
When you convert a Winform application into a WPF application – In a Winform or a Console application, you need a static Main method that acts as an entry point to your executable. In a WPF application, you do not require any such static class to be present at the compile time. You need an App.xaml file that appears something like this
1
2
3
4
5
6
7
8
| < Application x:Class = "MyWPFApplication.App" xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x = "http://schemas.microsoft.com/winfx/2006/xaml" StartupUri = "MainWindow1.xaml" > < Application.Resources > </ Application.Resources > </ Application > |
Here StartupUri represents the first/launch WPF Window or a Page and the App.xaml.cs is very short and simple
1
2
3
4
5
6
7
8
9
10
11
12
| using System.Windows; namespace MyWPFApplication { /// /// Interaction logic for App.xaml /// |
public
partial
class
App : Application
{
}
}
When you migrate a Winform application to WPF application, you can add this file explicitly to your project to get started. But when you would compile, you will find a compilation issue
Program does not contain a static ‘Main’ method suitable for an entry point
So the compiler treats App.xaml just like any other WPF page instead of a special class which we call it as ApplicationDefinition class.
What is the fix?
Check the properties of App.xaml. Change the Build Action to ApplicationDefinition and re-compile.
This also means, you can have any XAML file to be your ApplicationDefinition file. But it is preferable to name it App.xaml since it is industry standard and adds consistency to all your projects.