【www.bbyears.com--WPF】
Windows窗体应用程序的入口函数在Program.cs文件中,但WPF应用程序没有这个文件,WPF应用程序入口函数在哪里呢?手工添加一个入口函数,生成项目,出错:
原来WPF应用程序入口函数在objReleaseApp.g.cs文件中:
程序代码
代码如下public partial class App : System.Windows.Application {
///
/// InitializeComponent
///
[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
}
///
/// Application Entry Point.
///
[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();
}
}
从代码可知,InitializeComponent方法中的StartupUri用于指定WPF应用程序主窗体,假如需修改主窗体是不是这里改一下就可以了?不行!App.g.cs注释有说明:
引用内容
//------------------------------------------------------------------------------
//
// 此代码由工具生成。
// 运行时版本:4.0.30319.18052
//
// 对此文件的更改可能会导致不正确的行为,并且如果
// 重新生成代码,这些更改将会丢失。
//
//------------------------------------------------------------------------------
WPF应用程序主窗体应在App.xaml文件中修改:
代码如下 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml">