Replacing the WPF entry point

前端 未结 5 881
刺人心
刺人心 2020-11-29 20:06

WPF defines its own Main() method. How should I go about replacing it with my own Main method that (normally) opens the WPF MainWindow

5条回答
  •  醉话见心
    2020-11-29 20:56

    Create new class with your custom static Main method. At the end of this method just call original App.Main() generated by WPF:

    public class Program
    {
        [STAThread]
        public static void Main(string[] args)
        {
            // Your initialization code
            App.Main();
        }
    }
    

    Then set your project’s “Startup object” setting to the class containing your static Main().

提交回复
热议问题