Search code examples
c#wpfc#-4.0program-entry-point

No Main() in WPF?


I am a beginner when it comes to programming but I was sure that one of the universal rules was that a program starts with Main(). I do not see one when I create a WPF project. Is Main() simply named something differently in WPF?


Solution

  • It is generated during build, but you can provide your own (disambiguating it in project-properties as necessary). Look in obj/debug for an app file; I have (courtesy of "C# 2010 Express") App.g.i.cs with:

    namespace WpfApplication1 {
    
    
        /// <summary>
        /// App
        /// </summary>
        [System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "4.0.0.0")]
        public partial class App : System.Windows.Application {
    
            /// <summary>
            /// InitializeComponent
            /// </summary>
            [System.Diagnostics.DebuggerNonUserCodeAttribute()]
            public void InitializeComponent() {
    
                #line 4 "..\..\..\App.xaml"
                this.StartupUri = new System.Uri("MainWindow.xaml", System.UriKind.Relative);
    
                #line default
                #line hidden
            }
    
            /// <summary>
            /// Application Entry Point.
            /// </summary>
            [System.STAThreadAttribute()]
            [System.Diagnostics.DebuggerNonUserCodeAttribute()]
            public static void Main() {
                WpfApplication1.App app = new WpfApplication1.App();
                app.InitializeComponent();
                app.Run();
            }
        }
    }