我可以阻止生成 App.g.i.cs 吗? [英] Can I prevent App.g.i.cs to be generated?

查看:37
本文介绍了我可以阻止生成 App.g.i.cs 吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据 http://stuff.seans.com/2008/07/11/hello-wpf-world-part-1/,自动生成.

我可以阻止创建它以便我可以创建自己的版本吗?

Can I prevent to create it so that I can create my own version ?

推荐答案

App.gics 中包含一个函数 Main() 是应用程序的标准入口点它是自动创建的.如果需要,您可以提供自己的类来实现 Main() 链接:

In App.g.i.cs contains a function Main() is a standard entry point for an application and it is created automatically. If you want, you can provide your own class that implements Main() Link:

我们可以编写一些其他类,例如 Window1.xaml.cs.然后系统如何识别应该调用哪个 Main().那太简单了.转到项目属性,选择应用程序选项卡,然后将启动对象更改为 Window1.cs.

We can write in some other classes like Window1.xaml.cs. Then how the system identifies which Main() should get called. That too simple. Go to project properties, select application tab, then change the start up object to Window1.cs.

这里是三种方法添加您自己的 App.xaml 实现:

方法一

您可以删除现有的 App.xamlApp.xaml.cs 并添加一个新的类文件,并可能将其命名为 App.cs.在这里,您可以定义 App 类并编写您自己的 Main 方法,如下所示.

You can delete the existing App.xaml and App.xaml.cs and add a new class file and maybe call it App.cs. In this you can define the App class and write your own Main method as below.

方法二

如果您将资源和资源字典添加到 App.xaml,您将遇到方法 1 的问题.由于 App.xaml 不再存在,您必须在 App.cs 本身中编写代码来管理资源和合并的字典.但是,通过修改 .csproj 文件并将 App.xaml 标记为 Page 而不是 ApplicationDefinition 可以更轻松地处理此问题.

You will run into issues with Approach 1 if you are adding resources and resource dictionaries to your App.xaml. Since the App.xaml is no longer present you will have to write code in your App.cs itself to manage the resources and the merged dictionaries. However this can be more easily handled by modifying the .csproj file and marking App.xaml as Page instead of ApplicationDefinition.

方法 3

如果您有资源并因此想要拥有 App.xaml,但不喜欢篡改 .csproj 文件,那么您可以在项目中包含另一个类,该类定义如下 Main 方法.

If you have resources and hence want to have App.xaml, but don't like to tamper with .csproj file, then you can include another class in your project that defines the Main method as below.

另外,你可以看到这个链接:

Also, you can see this link:

没有 App.xaml 仍然可以使用 Blend

这篇关于我可以阻止生成 App.g.i.cs 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆