WPF-App.g.cs中Main的关闭自动生成 [英] WPF - Shut-off autogen of Main in App.g.cs
问题描述
我正在学习WPF.
我想在App.xaml.cs中提供自己的Main方法,而不是在App.g.cs中为我生成一个方法.但是,由于没有找到如何阻止生成其他Main的主因,因此不断发生冲突.
I want to provide my own Main method in my App.xaml.cs rather than getting one generated for me in App.g.cs. However I keep getting conflicts because I haven't found out how to stop an additional Main from being generated.
我的项目文件或其他地方是否有控制该设置的设置?
Is there a setting in my project file or elsewhere that controls this?
推荐答案
I found the answer here. http://learnwpf.com/post/2007/12/13/How-can-I-provide-my-own-Main%28%29-method-in-my-WPF-application.aspx
是:
WPF知道为特定xaml文件创建Main()方法的方法是通过为App.xaml设置的生成操作属性-它具有ApplicationDefinition的生成操作.将其更改为Page WPF不会创建Main方法,您可以在添加到项目中的常规类文件中提供自己的方法.
The way WPF knows to create the Main() method for a particular xaml file is through the build action property set for App.xaml - it has a build action of ApplicationDefinition. By changing this to Page WPF won't create the Main method and you can provide your own in a regular class file you add to the project.
但是,在上述博客的评论中,有一条评论指出,blend可能存在问题,它引用了以下内容:
However in the comments to the above blog, a comment notes there may be issues with blend and it references: http://blogs.msdn.com/expression/archive/2008/04/09/creating-a-wpf-blend-project-that-loads-resources-in-code.aspx . I don't fully understand the issues yet.
这篇关于WPF-App.g.cs中Main的关闭自动生成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!