wpf 类型名称“App”不存在于类型中...重命名 MainWindow 后发生
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4480087/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
wpf The type name 'App' does not exist in the type ... occurs after renaming MainWindow
提问by user310291
In a simple WPF, I have renamed MainWindow class to MyClass and I got this error in App.g.cs:
在一个简单的 WPF 中,我已将 MainWindow 类重命名为 MyClass,并且在 App.g.cs 中出现此错误:
public static void Main() {
MyClass.App app = new MyClass.App();
app.InitializeComponent();
app.Run();
}
How can I fix this can't find anything on the internet ?
我该如何解决这个在互联网上找不到任何东西?
回答by Johan Larsson
I accidentally got this error, in my case I had a class with the same name as the namespace. Renaming the class solved the problem.
我不小心收到了这个错误,就我而言,我有一个与命名空间同名的类。重命名类解决了这个问题。
回答by Legends
Do not name a class the same as its namespace
Check out if you don't have a class somewhere in your project that has the same name as your namespace!
检查您的项目中是否没有与命名空间同名的类!
for example:
例如:
namespace HashCalculator
{
public class HashCalculator
回答by Tergiver
App.g.cs is produced by compiling App.xaml into C# code. The problem is in your App.xaml. Without seeing it, I can't be sure exactly what, but you probably just need to alter the StartupUri to StartupUri="MyClass.xaml"
.
App.g.cs 是通过将 App.xaml 编译成 C# 代码生成的。问题出在您的 App.xaml 中。没有看到它,我无法确定到底是什么,但您可能只需要将 StartupUri 更改为StartupUri="MyClass.xaml"
.
回答by thumbmunkeys
You forgot to change the classname in MyClass.xaml (or MainWindow.xaml).
您忘记更改 MyClass.xaml(或 MainWindow.xaml)中的类名。
change it from
改变它
<Window x:Class="YourNamespace.MainWindow"
to
到
<Window x:Class="YourNamespace.MyClass"