The portal function for a Windows Forms application is in the Program.cs file, but where is the WPF application Portal function when the WPF application does not have this file? Add a portal function manually, build the project, and make an error:
The original WPF Application entry function is in the Objreleaseapp.g.cs file:
Program code
The code is as follows |
Copy Code |
Public partial class App:System.Windows.Application {
<summary> InitializeComponent </summary> [System.Diagnostics.DebuggerNonUserCodeAttribute ()] [System.CodeDom.Compiler.GeneratedCodeAttribute ("PresentationBuildTasks", "4.0.0.0")] public void InitializeComponent () {
#line 4 ". \.. \app.xaml " This. StartupUri = new System.Uri ("MainWindow.xaml", System.UriKind.Relative);
#line default #line hidden }
<summary> Application Entry point. </summary> [System.STAThreadAttribute ()] [System.Diagnostics.DebuggerNonUserCodeAttribute ()] [System.CodeDom.Compiler.GeneratedCodeAttribute ("PresentationBuildTasks", "4.0.0.0")] public static void Main () { Wpfapplication1.app App = new Wpfapplication1.app (); App. InitializeComponent (); App. Run (); } } |
As you can see from the code, the StartupUri in the InitializeComponent method is used to specify the main form of the WPF application, and if you need to modify the main form is this a change here? No way! App.g.cs Note:
Reference content
//------------------------------------------------------------------------------
<auto-generated>
This code is generated by the tool.
Run-time Version: 4.0.30319.18052
//
Changes to this file may cause incorrect behavior, and if
The code is regenerated, and these changes will be lost.
</auto-generated>
//------------------------------------------------------------------------------
The WPF Application main form should be modified in the App.xaml file:
code is as follows |
copy code |
<application x:class=" Wpfapplication1.app " xmlns= "http://schemas.microsoft.com/winfx/2006/xaml/ Presentation " xmlns:x=" http:// Schemas.microsoft.com/winfx/2006/xaml " startupuri= "MainWindow.xaml" <application.resources> </application.resources> </application |