To create a custom application class

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.