What is the entry point of a WPF application?

后端 未结 4 791
长情又很酷
长情又很酷 2020-12-29 01:35

The Main method is the entry point of a C# console application. Thus, for example, if I have to start some threads or services, I will do it within the Ma

4条回答
  •  孤城傲影
    2020-12-29 02:08

    The Main for a WPF application is autogenerated and can be found in one of the .cs files that backs your App.xaml file. You can expand App.xaml -> App.xaml.cs -> App -> Main() in the solution explorer, which will get you to the App.g.i.cs source file, which contains your Main() function.

    This file is auto-generated, so rather than editing the Main there, I would recommend creating a new .cs file in your project that contains the Main() function. You then have to change the properties of your project to specify the correct startup object. This is done on the Application tab in your project properties. Set it to the class that contains your custom Main function.

    You probably want to copy the contains of the autogenerated Main into your new one, since you want your application to behave normally (show the main window, etc.).

提交回复
热议问题