[解决]XNA游戏程序启动页面改为WPF窗体所出现的错误

我计划将XNA Windows Game4程序 改为从WPF窗体程序启动,出现如下错误:

WPF error: does not contain a static 'Main' method suitable for an entry point does not contain a static 'Main' method suitable for an entry point


如果你当前项目中的App.xaml未自动生成,如你新一个Windows Game项目,
但你想启动窗体用WPF窗体,那么当你从别处拷一个App.xaml或新建一个这样的文件时,则会出现
这样的情况。

同样,当你在Visual Studio中删除App.xaml从别的位置拷贝一个后会出现的编译错误。

出现该问题的原因在于:

默认的App.xaml在属性页中的Build Action 是ApplicationDefinition,而拷贝过来的文件默认不是这样的。(如我拷贝过来后,该属性为 CodeAnalysisDictionary) 。

解决方法:

  将App.xaml的Build Action 设置为ApplicationDefinition,

  他才会为我们生成所需的静态Main方法,这样程序才能够正确的被编译。
 


  在"项目根目录\obj\x86\Debug\App.g.i.cs"文件中我们可以找到正确编译后生成的Main函数
   内容如下所示:(以WindowsGame1项目为例)
  /// <summary>
        /// Application Entry Point.
        /// </summary>
        [System.STAThreadAttribute()]
        [System.Diagnostics.DebuggerNonUserCodeAttribute()]
        public static void Main() {
            WindowsGame1.App app = new WindowsGame1.App();
            app.InitializeComponent();
            app.Run();
        }

原文地址:https://www.cnblogs.com/furenjun/p/xnawpf.html