WPF how to redefine the Main function

I believe we all know, has been the Main function as the entry point of the program, and in the development of WPF project, some initialization operation is executed wanted to go on the Main, it was like to try to re-write if a Main function, the program will not execute, but the results unfortunately.

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;

namespace ProductManage
{
    /// <summary>
    /// App.xaml 的交互逻辑
    /// </summary>
    public partial class App : Application
    {
        /// <summary>
        /// Application Entry Point.
        /// </summary>
        [System.STAThreadAttribute()]
        [System.Diagnostics.DebuggerNonUserCodeAttribute()]
        [System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "4.0.0.0")]
        public static void Main()
        {        
     
            ProductManage.App app = new ProductManage.App();
            app.InitializeComponent();
            app.Run();
        }
    }
}

Offer will be completed after compiling the following error:

This shows that there is already a Main function, and will repeat the definition of compilation errors;

  /// <summary>
        /// Application Entry Point.
        /// </summary>
        [System.STAThreadAttribute()]
        [System.Diagnostics.DebuggerNonUserCodeAttribute()]
        [System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "4.0.0.0")]
        public static void Main() {
            ProductManage.App app = new ProductManage.App();
            app.InitializeComponent();
            app.Run();
        }

Now repeat, then delete the original Main functions are not on line yet, and then delete finished, re-run, really run properly; but this time the project then recompile the Main function duplicate definition errors will occur, palliative.

Here is the correct solution to repeat the definition of Main function

Once you find the following Main function delete

Then right Project -> Properties obtained as follows: to read Application.App

Finally Right App.xml: generation operation changed Page, and then rebuild the project can be.

 

Guess you like

Origin www.cnblogs.com/QingYiShouJiuRen/p/11323049.html