Because each application must create a Application object, VS provides the developer with a template to mitigate the duplication of effort by the developer. When using VS to create a WPF application, VS will automatically create a App.xaml file,
<Applicationx:class= "Wpfapplication8.app"xmlns= "Http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x= "Http://schemas.microsoft.com/winfx/2006/xaml"xmlns:local= "Clr-namespace:wpfapplication8"StartupUri= "MainWindow.xaml"> <application.resources> </application.resources></Application>
The StartupUri property in the claim code is used to specify the XAML file that will be the main window of the application, and the App.xaml file also has a post file that is associated with the XAML code.
Derived class derived from the XAML root element. So, as you can see from App.xaml.cs, the app class is a derived class derived from the application class, but curiously, the post code doesn't find the main method, nor does it see the instantiation
The code for the Application class.
Like MainWindow.xaml, vs automatically generates a local class name of App.g.cs for App.xaml. After the application compiles, you can find this file from the Obj\debug folder. App.g.cs source code is as follows
Public Partial classApp:System.Windows.Application {/// <summary> ///InitializeComponent method Auto-generated code/// </summary>[System.Diagnostics.DebuggerNonUserCodeAttribute ()] [System.CodeDom.Compiler.GeneratedCodeAttribute ("PresentationBuildTasks","4.0.0.0")] Public voidInitializeComponent () {#line5 ". \.. \app.xaml " This. StartupUri =NewSystem.Uri ("MainWindow.xaml", System.UriKind.Relative); #lineDefault#lineHidden } /// <summary> ///application Entry point. /// </summary> ///vs Plantar report The entry point of the generated application[ System.STAThreadAttribute ()] [System.Diagnostics.DebuggerNonUserCodeAttribute ()] [System.codedo M.compiler.generatedcodeattribute ("PresentationBuildTasks","4.0.0.0")] Public Static voidMain () {//create an instance of a derived child application classWpfapplication8.app App =NewWpfapplication8.app (); App. InitializeComponent (); App. Run (); } }}
In this auto-generated local class, you can see that a main method has been created as an entry point for the application, the main method first instantiates an App object, and then calls the static InitializeComponent method. In this method, just to set the startup property for the application class, for the property
A URI that gives a relative path to the XAML file.
To create a custom application class